mongrep 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/mongrep/query_result.rb +3 -3
- data/lib/mongrep/repository.rb +14 -6
- data/lib/mongrep/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa6b0fce568b4484935274059fdba1ce626f70cf
|
4
|
+
data.tar.gz: 7fbc40777a0d8d414b725da61913d010a1fb8a29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fea422283238f29c5d8e193a27e73648c4d82ce88c665b2f911d9a295f92833455743b6b71c47f6d3939d77e82a81a95723bb62909d5c76860b9b00c8e7bfdc4
|
7
|
+
data.tar.gz: 7d6e2cab262ce206e7700e1a22665cca64fa4fa0e110eb855cb936332ca47fcd3ad84ce6c93e3b1b9e584478efde94c856b98e423dd171d9afef7a9ecb87808d
|
data/README.md
CHANGED
data/lib/mongrep/query_result.rb
CHANGED
@@ -10,8 +10,8 @@ module Mongrep
|
|
10
10
|
|
11
11
|
attr_reader :model_class
|
12
12
|
# @api private
|
13
|
-
def initialize(collection_view,
|
14
|
-
@
|
13
|
+
def initialize(collection_view, &initialize_model)
|
14
|
+
@initialize_model = initialize_model
|
15
15
|
@collection_view = collection_view
|
16
16
|
end
|
17
17
|
|
@@ -45,7 +45,7 @@ module Mongrep
|
|
45
45
|
|
46
46
|
begin
|
47
47
|
@collection_view.each do |document|
|
48
|
-
yield @
|
48
|
+
yield @initialize_model.call(document)
|
49
49
|
end
|
50
50
|
ensure
|
51
51
|
@collection_view.close_query
|
data/lib/mongrep/repository.rb
CHANGED
@@ -32,14 +32,19 @@ module Mongrep
|
|
32
32
|
@collection = mongo_client[collection_name]
|
33
33
|
end
|
34
34
|
|
35
|
-
# Derives the model class from the class name
|
36
|
-
#
|
35
|
+
# Derives the model class from the class name and instanciates a model of
|
36
|
+
# that class with the given document. This is passed to a QueryResult
|
37
|
+
# which uses it to return model instances. It should be overridden when
|
38
|
+
# implementing polymorphism based on a field in the document.
|
39
|
+
# @return [Model] A model instance
|
37
40
|
# @example
|
38
41
|
# repository = Shop::ShoppingCarts.new(mongo_client)
|
39
|
-
# repository.
|
40
|
-
|
42
|
+
# repository.initialize_model(document)
|
43
|
+
# #=> #<Shop::Models::ShoppingCart:... >
|
44
|
+
def initialize_model(document)
|
41
45
|
model_name = self.class.name.demodulize.singularize
|
42
|
-
Mongrep.models_namespace.const_get(model_name)
|
46
|
+
model_class = Mongrep.models_namespace.const_get(model_name)
|
47
|
+
model_class.new(document)
|
43
48
|
end
|
44
49
|
|
45
50
|
# Finds documents matching the given query
|
@@ -179,7 +184,10 @@ module Mongrep
|
|
179
184
|
|
180
185
|
def execute_query(query_object, options)
|
181
186
|
check_query_type!(query_object)
|
182
|
-
QueryResult.new(
|
187
|
+
QueryResult.new(
|
188
|
+
collection.find(query_object.to_h, options),
|
189
|
+
&method(:initialize_model)
|
190
|
+
)
|
183
191
|
end
|
184
192
|
|
185
193
|
def check_persistence!(model)
|
data/lib/mongrep/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongrep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joakim Reinert
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|