lotus-model 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +52 -168
- data/EXAMPLE.md +35 -40
- data/README.md +152 -12
- data/lib/lotus/entity.rb +107 -24
- data/lib/lotus/model.rb +169 -8
- data/lib/lotus/model/adapters/abstract.rb +3 -2
- data/lib/lotus/model/adapters/file_system_adapter.rb +272 -0
- data/lib/lotus/model/adapters/implementation.rb +1 -1
- data/lib/lotus/model/adapters/memory/command.rb +2 -1
- data/lib/lotus/model/adapters/memory/query.rb +49 -10
- data/lib/lotus/model/adapters/memory_adapter.rb +13 -5
- data/lib/lotus/model/adapters/null_adapter.rb +20 -0
- data/lib/lotus/model/adapters/sql/collection.rb +18 -18
- data/lib/lotus/model/adapters/sql/query.rb +23 -3
- data/lib/lotus/model/config/adapter.rb +108 -0
- data/lib/lotus/model/config/mapper.rb +45 -0
- data/lib/lotus/model/configuration.rb +187 -0
- data/lib/lotus/model/mapper.rb +26 -3
- data/lib/lotus/model/mapping.rb +24 -0
- data/lib/lotus/model/mapping/coercer.rb +3 -3
- data/lib/lotus/model/mapping/coercions.rb +30 -0
- data/lib/lotus/model/mapping/collection.rb +127 -9
- data/lib/lotus/model/version.rb +1 -1
- data/lib/lotus/repository.rb +19 -11
- data/lotus-model.gemspec +2 -1
- metadata +16 -5
data/lib/lotus/model/version.rb
CHANGED
data/lib/lotus/repository.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'lotus/utils/class_attribute'
|
2
|
+
require 'lotus/model/adapters/null_adapter'
|
2
3
|
|
3
4
|
module Lotus
|
4
5
|
# Mediates between the entities and the persistence layer, by offering an API
|
@@ -6,7 +7,7 @@ module Lotus
|
|
6
7
|
#
|
7
8
|
#
|
8
9
|
#
|
9
|
-
#
|
10
|
+
# By default, a repository is named after an entity, by appending the
|
10
11
|
# `Repository` suffix to the entity class name.
|
11
12
|
#
|
12
13
|
# @example
|
@@ -26,7 +27,17 @@ module Lotus
|
|
26
27
|
# include Lotus::Repository
|
27
28
|
# end
|
28
29
|
#
|
30
|
+
# Repository for an entity can be configured by setting # the `#repository`
|
31
|
+
# on the mapper.
|
29
32
|
#
|
33
|
+
# @example
|
34
|
+
# # PostRepository is repository for Article
|
35
|
+
# mapper = Lotus::Model::Mapper.new do
|
36
|
+
# collection :articles do
|
37
|
+
# entity Article
|
38
|
+
# repository PostRepository
|
39
|
+
# end
|
40
|
+
# end
|
30
41
|
#
|
31
42
|
# A repository is storage independent.
|
32
43
|
# All the queries and commands are delegated to the current adapter.
|
@@ -124,6 +135,7 @@ module Lotus
|
|
124
135
|
include Lotus::Utils::ClassAttribute
|
125
136
|
|
126
137
|
class_attribute :collection
|
138
|
+
self.adapter = Lotus::Model::Adapters::NullAdapter.new
|
127
139
|
end
|
128
140
|
end
|
129
141
|
|
@@ -241,6 +253,7 @@ module Lotus
|
|
241
253
|
# article.title # => "Launching Lotus::Model"
|
242
254
|
def persist(entity)
|
243
255
|
@adapter.persist(collection, entity)
|
256
|
+
entity
|
244
257
|
end
|
245
258
|
|
246
259
|
# Creates a record in the database for the given entity.
|
@@ -404,26 +417,21 @@ module Lotus
|
|
404
417
|
#
|
405
418
|
# @param id [Object] the identity of the entity
|
406
419
|
#
|
407
|
-
# @return [Object] the result of the query
|
408
|
-
#
|
409
|
-
# @raise [Lotus::Model::EntityNotFound] if the entity cannot be found.
|
420
|
+
# @return [Object,NilClass] the result of the query, if present
|
410
421
|
#
|
411
422
|
# @since 0.1.0
|
412
423
|
#
|
413
|
-
# @
|
414
|
-
#
|
415
|
-
# @example With a persisted entity
|
424
|
+
# @example
|
416
425
|
# require 'lotus/model'
|
417
426
|
#
|
418
427
|
# class ArticleRepository
|
419
428
|
# include Lotus::Repository
|
420
429
|
# end
|
421
430
|
#
|
422
|
-
# ArticleRepository.find(
|
431
|
+
# ArticleRepository.find(23) # => #<Article:0x007f9b19a60098>
|
432
|
+
# ArticleRepository.find(9999) # => nil
|
423
433
|
def find(id)
|
424
|
-
@adapter.find(collection, id)
|
425
|
-
raise Lotus::Model::EntityNotFound.new unless record
|
426
|
-
end
|
434
|
+
@adapter.find(collection, id)
|
427
435
|
end
|
428
436
|
|
429
437
|
# Returns the first entity in the database.
|
data/lotus-model.gemspec
CHANGED
@@ -17,8 +17,9 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
|
+
spec.required_ruby_version = '>= 2.0.0'
|
20
21
|
|
21
|
-
spec.add_runtime_dependency 'lotus-utils', '~> 0.2'
|
22
|
+
spec.add_runtime_dependency 'lotus-utils', '~> 0.3', '>= 0.3.2'
|
22
23
|
spec.add_runtime_dependency 'sequel', '~> 4.9'
|
23
24
|
|
24
25
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lotus-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lotus-utils
|
@@ -16,14 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.3.2
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
29
|
+
version: '0.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.3.2
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: sequel
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,15 +102,20 @@ files:
|
|
96
102
|
- lib/lotus/entity.rb
|
97
103
|
- lib/lotus/model.rb
|
98
104
|
- lib/lotus/model/adapters/abstract.rb
|
105
|
+
- lib/lotus/model/adapters/file_system_adapter.rb
|
99
106
|
- lib/lotus/model/adapters/implementation.rb
|
100
107
|
- lib/lotus/model/adapters/memory/collection.rb
|
101
108
|
- lib/lotus/model/adapters/memory/command.rb
|
102
109
|
- lib/lotus/model/adapters/memory/query.rb
|
103
110
|
- lib/lotus/model/adapters/memory_adapter.rb
|
111
|
+
- lib/lotus/model/adapters/null_adapter.rb
|
104
112
|
- lib/lotus/model/adapters/sql/collection.rb
|
105
113
|
- lib/lotus/model/adapters/sql/command.rb
|
106
114
|
- lib/lotus/model/adapters/sql/query.rb
|
107
115
|
- lib/lotus/model/adapters/sql_adapter.rb
|
116
|
+
- lib/lotus/model/config/adapter.rb
|
117
|
+
- lib/lotus/model/config/mapper.rb
|
118
|
+
- lib/lotus/model/configuration.rb
|
108
119
|
- lib/lotus/model/mapper.rb
|
109
120
|
- lib/lotus/model/mapping.rb
|
110
121
|
- lib/lotus/model/mapping/coercer.rb
|
@@ -125,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
136
|
requirements:
|
126
137
|
- - ">="
|
127
138
|
- !ruby/object:Gem::Version
|
128
|
-
version:
|
139
|
+
version: 2.0.0
|
129
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
141
|
requirements:
|
131
142
|
- - ">="
|