mongodoc 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/Rakefile +21 -0
  2. data/TODO +6 -1
  3. data/VERSION +1 -1
  4. data/features/finders.feature +1 -1
  5. data/features/mongodoc_base.feature +11 -2
  6. data/features/{named_scopes.feature → scopes.feature} +0 -0
  7. data/features/step_definitions/document_steps.rb +15 -4
  8. data/features/step_definitions/documents.rb +3 -3
  9. data/features/step_definitions/query_steps.rb +17 -14
  10. data/features/step_definitions/{named_scope_steps.rb → scope_steps.rb} +0 -0
  11. data/features/using_criteria.feature +22 -43
  12. data/lib/mongodoc.rb +1 -1
  13. data/lib/mongodoc/associations/collection_proxy.rb +3 -1
  14. data/lib/mongodoc/associations/document_proxy.rb +4 -1
  15. data/lib/mongodoc/associations/hash_proxy.rb +3 -1
  16. data/lib/mongodoc/associations/proxy_base.rb +6 -4
  17. data/lib/mongodoc/attributes.rb +6 -6
  18. data/lib/mongodoc/contexts.rb +24 -0
  19. data/lib/mongodoc/contexts/enumerable.rb +132 -0
  20. data/lib/mongodoc/contexts/mongo.rb +215 -0
  21. data/lib/mongodoc/criteria.rb +36 -479
  22. data/lib/mongodoc/document.rb +3 -2
  23. data/lib/mongodoc/finders.rb +31 -11
  24. data/lib/mongodoc/matchers.rb +35 -0
  25. data/lib/mongodoc/scope.rb +64 -0
  26. data/lib/mongoid/contexts/paging.rb +42 -0
  27. data/lib/mongoid/criteria.rb +264 -0
  28. data/lib/mongoid/criterion/complex.rb +21 -0
  29. data/lib/mongoid/criterion/exclusion.rb +65 -0
  30. data/lib/mongoid/criterion/inclusion.rb +92 -0
  31. data/lib/mongoid/criterion/optional.rb +136 -0
  32. data/lib/mongoid/extensions/hash/criteria_helpers.rb +20 -0
  33. data/lib/mongoid/extensions/symbol/inflections.rb +36 -0
  34. data/lib/mongoid/matchers/all.rb +11 -0
  35. data/lib/mongoid/matchers/default.rb +26 -0
  36. data/lib/mongoid/matchers/exists.rb +13 -0
  37. data/lib/mongoid/matchers/gt.rb +11 -0
  38. data/lib/mongoid/matchers/gte.rb +11 -0
  39. data/lib/mongoid/matchers/in.rb +11 -0
  40. data/lib/mongoid/matchers/lt.rb +11 -0
  41. data/lib/mongoid/matchers/lte.rb +11 -0
  42. data/lib/mongoid/matchers/ne.rb +11 -0
  43. data/lib/mongoid/matchers/nin.rb +11 -0
  44. data/lib/mongoid/matchers/size.rb +11 -0
  45. data/mongodoc.gemspec +39 -9
  46. data/spec/attributes_spec.rb +16 -2
  47. data/spec/contexts/enumerable_spec.rb +335 -0
  48. data/spec/contexts/mongo_spec.rb +148 -0
  49. data/spec/contexts_spec.rb +28 -0
  50. data/spec/criteria_spec.rb +15 -766
  51. data/spec/finders_spec.rb +28 -36
  52. data/spec/matchers_spec.rb +342 -0
  53. data/spec/scope_spec.rb +79 -0
  54. metadata +40 -10
  55. data/features/step_definitions/criteria_steps.rb +0 -42
  56. data/lib/mongodoc/named_scope.rb +0 -68
  57. data/spec/named_scope_spec.rb +0 -82
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Les Hill
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-02-16 00:00:00 -05:00
17
+ date: 2010-02-23 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -125,23 +125,22 @@ files:
125
125
  - features/finders.feature
126
126
  - features/mongodb.yml
127
127
  - features/mongodoc_base.feature
128
- - features/named_scopes.feature
129
128
  - features/new_record.feature
130
129
  - features/partial_updates.feature
131
130
  - features/removing_documents.feature
132
131
  - features/saving_an_object.feature
132
+ - features/scopes.feature
133
133
  - features/step_definitions/collection_steps.rb
134
- - features/step_definitions/criteria_steps.rb
135
134
  - features/step_definitions/document_steps.rb
136
135
  - features/step_definitions/documents.rb
137
136
  - features/step_definitions/finder_steps.rb
138
137
  - features/step_definitions/json_steps.rb
139
- - features/step_definitions/named_scope_steps.rb
140
138
  - features/step_definitions/object_steps.rb
141
139
  - features/step_definitions/objects.rb
142
140
  - features/step_definitions/partial_update_steps.rb
143
141
  - features/step_definitions/query_steps.rb
144
142
  - features/step_definitions/removing_documents_steps.rb
143
+ - features/step_definitions/scope_steps.rb
145
144
  - features/step_definitions/util_steps.rb
146
145
  - features/support/support.rb
147
146
  - features/using_criteria.feature
@@ -154,6 +153,9 @@ files:
154
153
  - lib/mongodoc/bson.rb
155
154
  - lib/mongodoc/collection.rb
156
155
  - lib/mongodoc/connection.rb
156
+ - lib/mongodoc/contexts.rb
157
+ - lib/mongodoc/contexts/enumerable.rb
158
+ - lib/mongodoc/contexts/mongo.rb
157
159
  - lib/mongodoc/criteria.rb
158
160
  - lib/mongodoc/cursor.rb
159
161
  - lib/mongodoc/document.rb
@@ -173,10 +175,30 @@ files:
173
175
  - lib/mongodoc/ext/symbol.rb
174
176
  - lib/mongodoc/ext/time.rb
175
177
  - lib/mongodoc/finders.rb
176
- - lib/mongodoc/named_scope.rb
178
+ - lib/mongodoc/matchers.rb
177
179
  - lib/mongodoc/query.rb
180
+ - lib/mongodoc/scope.rb
178
181
  - lib/mongodoc/validations/macros.rb
179
182
  - lib/mongodoc/validations/validates_embedded.rb
183
+ - lib/mongoid/contexts/paging.rb
184
+ - lib/mongoid/criteria.rb
185
+ - lib/mongoid/criterion/complex.rb
186
+ - lib/mongoid/criterion/exclusion.rb
187
+ - lib/mongoid/criterion/inclusion.rb
188
+ - lib/mongoid/criterion/optional.rb
189
+ - lib/mongoid/extensions/hash/criteria_helpers.rb
190
+ - lib/mongoid/extensions/symbol/inflections.rb
191
+ - lib/mongoid/matchers/all.rb
192
+ - lib/mongoid/matchers/default.rb
193
+ - lib/mongoid/matchers/exists.rb
194
+ - lib/mongoid/matchers/gt.rb
195
+ - lib/mongoid/matchers/gte.rb
196
+ - lib/mongoid/matchers/in.rb
197
+ - lib/mongoid/matchers/lt.rb
198
+ - lib/mongoid/matchers/lte.rb
199
+ - lib/mongoid/matchers/ne.rb
200
+ - lib/mongoid/matchers/nin.rb
201
+ - lib/mongoid/matchers/size.rb
180
202
  - mongod.example.yml
181
203
  - mongodb.example.yml
182
204
  - mongodoc.gemspec
@@ -191,6 +213,9 @@ files:
191
213
  - spec/bson_spec.rb
192
214
  - spec/collection_spec.rb
193
215
  - spec/connection_spec.rb
216
+ - spec/contexts/enumerable_spec.rb
217
+ - spec/contexts/mongo_spec.rb
218
+ - spec/contexts_spec.rb
194
219
  - spec/criteria_spec.rb
195
220
  - spec/cursor_spec.rb
196
221
  - spec/document_ext.rb
@@ -198,11 +223,12 @@ files:
198
223
  - spec/embedded_save_spec.rb
199
224
  - spec/finders_spec.rb
200
225
  - spec/hash_matchers.rb
226
+ - spec/matchers_spec.rb
201
227
  - spec/mongodb.yml
202
228
  - spec/mongodb_pairs.yml
203
- - spec/named_scope_spec.rb
204
229
  - spec/new_record_spec.rb
205
230
  - spec/query_spec.rb
231
+ - spec/scope_spec.rb
206
232
  - spec/spec.opts
207
233
  - spec/spec_helper.rb
208
234
  has_rdoc: true
@@ -231,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
257
  requirements: []
232
258
 
233
259
  rubyforge_project:
234
- rubygems_version: 1.3.6.pre.3
260
+ rubygems_version: 1.3.6
235
261
  signing_key:
236
262
  specification_version: 3
237
263
  summary: ODM for MongoDB
@@ -244,6 +270,9 @@ test_files:
244
270
  - spec/bson_spec.rb
245
271
  - spec/collection_spec.rb
246
272
  - spec/connection_spec.rb
273
+ - spec/contexts/enumerable_spec.rb
274
+ - spec/contexts/mongo_spec.rb
275
+ - spec/contexts_spec.rb
247
276
  - spec/criteria_spec.rb
248
277
  - spec/cursor_spec.rb
249
278
  - spec/document_ext.rb
@@ -251,9 +280,10 @@ test_files:
251
280
  - spec/embedded_save_spec.rb
252
281
  - spec/finders_spec.rb
253
282
  - spec/hash_matchers.rb
254
- - spec/named_scope_spec.rb
283
+ - spec/matchers_spec.rb
255
284
  - spec/new_record_spec.rb
256
285
  - spec/query_spec.rb
286
+ - spec/scope_spec.rb
257
287
  - spec/spec_helper.rb
258
288
  - examples/simple_document.rb
259
289
  - examples/simple_object.rb
@@ -1,42 +0,0 @@
1
- When /^I query (.*) with 'all'$/ do |doc|
2
- query(doc).all
3
- end
4
-
5
- When /^I query (.*) to select fields? "([^\"]*)"$/ do |doc, fields|
6
- fields = fields.split
7
- query(doc).only(*fields)
8
- end
9
-
10
- When /^I query (.*) where "([^\"]*)"$/ do |doc, where_text|
11
- where = eval(where_text)
12
- query(doc).where(where)
13
- end
14
-
15
- When /^I query (.*) that excludes "([^\"]*)"$/ do |doc, exclude_text|
16
- exclude = eval(exclude_text)
17
- query(doc).excludes(exclude)
18
- end
19
-
20
- When /^I set the query on (.*) to (limit|skip) (.*)$/ do |doc, op, count|
21
- query(doc).send(op, count.to_i)
22
- end
23
-
24
-
25
- When /^I query (.*) with (every|not in|in) "([^\"]*)"$/ do |doc, op, hash_text|
26
- hash = eval(hash_text)
27
- query(doc).send(op.gsub(' ', '_'), hash)
28
- end
29
-
30
- When /^I query (.*) with the '(.*)' id$/ do |doc, name|
31
- object = instance_variable_get("@#{name}")
32
- query(doc).id(object.id)
33
- end
34
-
35
- When /^I set the query extras limit on (.*) to (.*)$/ do |doc, count|
36
- query(doc).limit(count.to_i)
37
- end
38
-
39
- When /^I order the (.*) query by "([^\"]*)"$/ do |doc, order_text|
40
- order = eval(order_text)
41
- query(doc).order_by(order)
42
- end
@@ -1,68 +0,0 @@
1
- # Based on ActiveRecord::NamedScope
2
- module MongoDoc
3
- module NamedScope
4
- def scopes
5
- read_inheritable_attribute(:scopes) || write_inheritable_attribute(:scopes, {})
6
- end
7
-
8
- def named_scope(name, options = {}, &block)
9
- name = name.to_sym
10
- scopes[name] = lambda do |parent_scope, *args|
11
- CriteriaProxy.new(parent_scope, Hash === options ? options : options.call(*args), &block)
12
- end
13
- (class << self; self; end).class_eval <<-EOT
14
- def #{name}(*args)
15
- scopes[:#{name}].call(self, *args)
16
- end
17
- EOT
18
- end
19
-
20
- class CriteriaProxy
21
- attr_accessor :conditions, :klass, :parent_scope
22
-
23
- delegate :scopes, :to => :parent_scope
24
-
25
- def initialize(parent_scope, conditions, &block)
26
- conditions ||= {}
27
- [conditions.delete(:extend)].flatten.each { |extension| extend extension } if conditions.include?(:extend)
28
- extend Module.new(&block) if block_given?
29
- self.klass = parent_scope unless CriteriaProxy === parent_scope
30
- self.parent_scope, self.conditions = parent_scope, conditions
31
- end
32
-
33
- def respond_to?(method, include_private = false)
34
- super || if klass
35
- proxy_found.respond_to?(method, include_private)
36
- else
37
- parent_scope.respond_to?(method, include_private)
38
- end
39
- end
40
-
41
- protected
42
-
43
- def proxy_found
44
- @found || load_found
45
- end
46
-
47
- private
48
-
49
- def method_missing(method, *args, &block)
50
- if scopes.include?(method)
51
- scopes[method].call(self, *args)
52
- elsif klass
53
- proxy_found.send(method, *args, &block)
54
- else
55
- parent_scope.criteria(conditions)
56
- parent_scope.send(method, *args, &block)
57
- end
58
- end
59
-
60
- def load_found
61
- @found = Criteria.new(klass)
62
- @found.criteria(conditions)
63
- @found
64
- end
65
- end
66
- end
67
- end
68
-
@@ -1,82 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper.rb"))
2
-
3
- describe MongoDoc::NamedScope do
4
-
5
- module Extension
6
- def extension_module_method
7
- "extension module method"
8
- end
9
- end
10
-
11
- class NamedScopeTest
12
- include MongoDoc::Document
13
-
14
- key :active
15
- key :count
16
-
17
- named_scope :active, :where => {:active => true} do
18
- def extension_method
19
- "extension method"
20
- end
21
- end
22
- named_scope :count_gt_one, :where => {:count => {'$gt' => 1}}, :extend => Extension
23
- named_scope :at_least_count, lambda {|count| {:where => {:count => {'$gt' => count}}}}
24
- end
25
-
26
- context ".named_scope" do
27
- it "adds the named scope to the hash of scopes" do
28
- NamedScopeTest.scopes.should have_key(:active)
29
- end
30
-
31
- it "creates a class method for the named scope" do
32
- NamedScopeTest.should respond_to(:active)
33
- end
34
- end
35
-
36
- context "accessing a named scope" do
37
- it "is a criteria proxy" do
38
- MongoDoc::NamedScope::CriteriaProxy.should === NamedScopeTest.active
39
- end
40
-
41
- it "responds like a criteria" do
42
- NamedScopeTest.active.should respond_to(:selector)
43
- end
44
-
45
- it "instantiates the criteria" do
46
- criteria = MongoDoc::Criteria.new(NamedScopeTest)
47
- MongoDoc::Criteria.should_receive(:new).and_return(criteria)
48
- NamedScopeTest.active.selector
49
- end
50
-
51
- it "has set the conditions on the criteria" do
52
- NamedScopeTest.active.selector.should has_entry(:active => true)
53
- end
54
-
55
- it "sets the association extension by block" do
56
- NamedScopeTest.active.extension_method.should == "extension method"
57
- end
58
-
59
- it "sets the association extension by :extend" do
60
- NamedScopeTest.count_gt_one.extension_module_method.should == "extension module method"
61
- end
62
-
63
- context "when using a lambda" do
64
- it "accepts parameters to the criteria" do
65
- NamedScopeTest.at_least_count(3).selector.should has_entry(:count => {'$gt' => 3})
66
- end
67
- end
68
- end
69
-
70
- context "chained scopes" do
71
- it "instantiates the criteria" do
72
- criteria = MongoDoc::Criteria.new(NamedScopeTest)
73
- MongoDoc::Criteria.should_receive(:new).and_return(criteria)
74
- NamedScopeTest.active.count_gt_one.selector
75
- end
76
-
77
- it "merges the criteria" do
78
- NamedScopeTest.active.count_gt_one.selector.should has_entry(:count => {'$gt' => 1}, :active => true)
79
- end
80
- end
81
- end
82
-