mongo_odm 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,10 +1,10 @@
1
1
  # Use `bundle install` in order to install these gems
2
2
  source 'http://rubygems.org'
3
3
 
4
- gem "activesupport", "~>3.0.3"
5
- gem "activemodel", "~>3.0.3"
6
- gem "mongo", "~>1.2.0"
7
- gem "bson_ext", "~>1.2.0"
4
+ gem "activesupport", "~>3.0.4"
5
+ gem "activemodel", "~>3.0.4"
6
+ gem "mongo", "~>1.2.2"
7
+ gem "bson_ext", "~>1.2.2"
8
8
  gem "tzinfo", "~>0.3.24"
9
9
 
10
10
  group :development do
data/Gemfile.lock CHANGED
@@ -1,14 +1,20 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.0.3)
5
- activesupport (= 3.0.3)
4
+ ZenTest (4.4.2)
5
+ activemodel (3.0.4)
6
+ activesupport (= 3.0.4)
6
7
  builder (~> 2.1.2)
7
8
  i18n (~> 0.4)
8
- activesupport (3.0.3)
9
- bson (1.2.0)
10
- bson_ext (1.2.0)
9
+ activesupport (3.0.4)
10
+ archive-tar-minitar (0.5.2)
11
+ autotest (4.4.6)
12
+ ZenTest (>= 4.4.1)
13
+ bson (1.2.2)
14
+ bson_ext (1.2.2)
11
15
  builder (2.1.2)
16
+ columnize (0.3.2)
17
+ database_cleaner (0.6.3)
12
18
  diff-lcs (1.1.2)
13
19
  git (1.2.5)
14
20
  i18n (0.5.0)
@@ -16,8 +22,10 @@ GEM
16
22
  bundler (~> 1.0.0)
17
23
  git (>= 1.2.5)
18
24
  rake
19
- mongo (1.2.0)
20
- bson (>= 1.2.0)
25
+ linecache19 (0.5.11)
26
+ ruby_core_source (>= 0.1.4)
27
+ mongo (1.2.2)
28
+ bson (>= 1.2.2)
21
29
  rake (0.8.7)
22
30
  rcov (0.9.9)
23
31
  rspec (2.4.0)
@@ -28,6 +36,16 @@ GEM
28
36
  rspec-expectations (2.4.0)
29
37
  diff-lcs (~> 1.1.2)
30
38
  rspec-mocks (2.4.0)
39
+ ruby-debug-base19 (0.11.24)
40
+ columnize (>= 0.3.1)
41
+ linecache19 (>= 0.5.11)
42
+ ruby_core_source (>= 0.1.4)
43
+ ruby-debug19 (0.11.6)
44
+ columnize (>= 0.3.1)
45
+ linecache19 (>= 0.5.11)
46
+ ruby-debug-base19 (>= 0.11.19)
47
+ ruby_core_source (0.1.4)
48
+ archive-tar-minitar (>= 0.5.2)
31
49
  tzinfo (0.3.24)
32
50
  watchr (0.7)
33
51
  yard (0.6.4)
@@ -36,13 +54,16 @@ PLATFORMS
36
54
  ruby
37
55
 
38
56
  DEPENDENCIES
39
- activemodel (~> 3.0.3)
40
- activesupport (~> 3.0.3)
41
- bson_ext (~> 1.2.0)
57
+ activemodel (~> 3.0.4)
58
+ activesupport (~> 3.0.4)
59
+ autotest
60
+ bson_ext (~> 1.2.2)
61
+ database_cleaner
42
62
  jeweler (~> 1.5.2)
43
- mongo (~> 1.2.0)
63
+ mongo (~> 1.2.2)
44
64
  rcov (~> 0.9.9)
45
65
  rspec (= 2.4.0)
66
+ ruby-debug19
46
67
  tzinfo (~> 0.3.24)
47
68
  watchr (~> 0.7)
48
69
  yard (~> 0.6.4)
@@ -9,13 +9,12 @@ module MongoODM
9
9
  limit = opts.delete(:limit) || 0
10
10
  sort = opts.delete(:sort)
11
11
  hint = opts.delete(:hint)
12
- snapshot = opts.delete(:snapshot)
12
+ snapshot = opts.delete(:snapshot)
13
13
  batch_size = opts.delete(:batch_size)
14
+ timeout = (opts.delete(:timeout) == false) ? false : true
14
15
 
15
- if opts[:timeout] == false && !block_given?
16
- raise ArgumentError, "Timeout can be set to false only when #find is invoked with a block."
17
- else
18
- timeout = opts.delete(:timeout) || false
16
+ if timeout == false && !block_given?
17
+ raise ArgumentError, "Collection#find must be invoked with a block when timeout is disabled."
19
18
  end
20
19
 
21
20
  if hint
@@ -27,7 +26,8 @@ module MongoODM
27
26
  raise RuntimeError, "Unknown options [#{opts.inspect}]" unless opts.empty?
28
27
 
29
28
  cursor = MongoODM::Cursor.new(self, :selector => selector, :fields => fields, :skip => skip, :limit => limit,
30
- :order => sort, :hint => hint, :snapshot => snapshot, :timeout => timeout, :batch_size => batch_size)
29
+ :order => sort, :hint => hint, :snapshot => snapshot, :timeout => timeout, :batch_size => batch_size)
30
+
31
31
  if block_given?
32
32
  yield cursor
33
33
  cursor.close()
@@ -37,7 +37,7 @@ module MongoODM
37
37
  end
38
38
  end
39
39
 
40
- def find_and_modify(opts = {})
40
+ def find_and_modify(*args)
41
41
  MongoODM.instanciate(super)
42
42
  end
43
43
 
@@ -2,53 +2,53 @@
2
2
  module MongoODM
3
3
 
4
4
  class Criteria
5
- delegate :inspect, :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to => :to_a
6
-
5
+
6
+ delegate :inspect, :to_xml, :to_yaml, :to_json, :include?, :to => :to_a
7
+
7
8
  def initialize(klass, selector = {}, opts = {})
8
9
  @klass, @selector, @opts = klass, selector, opts
9
- @loaded = false
10
- end
11
-
12
- def find(selector = {}, opts = {})
13
- _merge_criteria(selector, opts)
14
- end
15
-
16
- def loaded?
17
- @loaded
10
+ _set_cursor
18
11
  end
12
+ attr_reader :selector, :opts, :cursor
19
13
 
20
14
  def ==(other)
21
15
  case other
22
16
  when Criteria
23
17
  other.instance_variable_get("@selector") == @selector &&
24
18
  other.instance_variable_get("@opts") == @opts
25
- when Array
19
+ else
26
20
  to_a == other.to_a
27
21
  end
28
22
  end
29
23
 
30
- def method_missing(method_name, *args, &block)
31
- if Array.method_defined?(method_name)
32
- to_a.send(method_name, *args, &block)
33
- elsif @klass.methods.include?(method_name)
34
- result = @klass.send(method_name, *args, &block)
35
- if result.is_a?(Criteria)
36
- selector = result.instance_variable_get("@selector")
37
- opts = result.instance_variable_get("@opts")
38
- _merge_criteria(selector, opts)
39
- else
40
- result
41
- end
42
- else
43
- @klass.collection.find(@selector, @opts).send(method_name, *args)
44
- end
24
+ def to_a
25
+ @cursor.to_a
26
+ end
27
+
28
+ def _set_cursor
29
+ @cursor = @klass.collection.find(@selector, @opts)
45
30
  end
46
31
 
47
32
  def _merge_criteria(selector, opts)
48
33
  @selector.merge!(selector)
49
34
  @opts.merge!(opts)
35
+ _set_cursor
50
36
  self
51
37
  end
38
+
39
+ def method_missing(method_name, *args, &block)
40
+ if @klass.respond_to?(method_name)
41
+ result = @klass.send(method_name, *args, &block)
42
+ result.is_a?(Criteria) ? _merge_criteria(result.selector, result.opts) : result
43
+ elsif @cursor.respond_to?(method_name)
44
+ @cursor.send(method_name, *args, &block)
45
+ elsif [].respond_to?(method_name)
46
+ to_a.send(method_name, *args, &block)
47
+ else
48
+ super
49
+ end
50
+ end
51
+
52
52
  end
53
53
 
54
54
  end
@@ -69,7 +69,7 @@ module MongoODM
69
69
  @collection ||= if self.superclass.included_modules.include?(MongoODM::Document)
70
70
  self.superclass.collection
71
71
  else
72
- MongoODM::Collection.new(MongoODM.database, name.tableize)
72
+ MongoODM::Collection.new(name.tableize, MongoODM.database)
73
73
  end
74
74
  end
75
75
 
@@ -78,14 +78,20 @@ module MongoODM
78
78
  when MongoODM::Collection
79
79
  name_or_collection
80
80
  when String, Symbol
81
- MongoODM::Collection.new(MongoODM.database, name_or_collection)
81
+ MongoODM::Collection.new(name_or_collection, MongoODM.database)
82
82
  else
83
83
  raise "MongoODM::Collection instance or valid collection name required"
84
84
  end
85
85
  end
86
86
 
87
87
  def find(*args)
88
- MongoODM::Criteria.new(self, *args)
88
+ if args.size == 1 && args.first.is_a?(String)
89
+ MongoODM::Criteria.new(self, :_id => BSON::ObjectId.from_string(args.first))
90
+ elsif args.size == 1 && args.first.is_a?(BSON::ObjectId)
91
+ MongoODM::Criteria.new(self, :_id => args.first)
92
+ else
93
+ MongoODM::Criteria.new(self, *args)
94
+ end
89
95
  end
90
96
 
91
97
  def destroy_all(*args)
@@ -2,6 +2,6 @@
2
2
  module MongoODM
3
3
  VERSION_MAJOR = "0"
4
4
  VERSION_MINOR = "2"
5
- VERSION_BUILD = "5"
5
+ VERSION_BUILD = "6"
6
6
  VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_BUILD}"
7
7
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_odm
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 5
9
- version: 0.2.5
4
+ prerelease:
5
+ version: 0.2.6
10
6
  platform: ruby
11
7
  authors:
12
8
  - Carlos Paramio
@@ -14,306 +10,228 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-01-20 00:00:00 +01:00
13
+ date: 2011-02-20 00:00:00 +01:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
17
  name: activesupport
22
- prerelease: false
23
18
  requirement: &id001 !ruby/object:Gem::Requirement
24
19
  none: false
25
20
  requirements:
26
21
  - - ~>
27
22
  - !ruby/object:Gem::Version
28
- segments:
29
- - 3
30
- - 0
31
- - 3
32
- version: 3.0.3
23
+ version: 3.0.4
33
24
  type: :runtime
25
+ prerelease: false
34
26
  version_requirements: *id001
35
27
  - !ruby/object:Gem::Dependency
36
28
  name: activemodel
37
- prerelease: false
38
29
  requirement: &id002 !ruby/object:Gem::Requirement
39
30
  none: false
40
31
  requirements:
41
32
  - - ~>
42
33
  - !ruby/object:Gem::Version
43
- segments:
44
- - 3
45
- - 0
46
- - 3
47
- version: 3.0.3
34
+ version: 3.0.4
48
35
  type: :runtime
36
+ prerelease: false
49
37
  version_requirements: *id002
50
38
  - !ruby/object:Gem::Dependency
51
39
  name: mongo
52
- prerelease: false
53
40
  requirement: &id003 !ruby/object:Gem::Requirement
54
41
  none: false
55
42
  requirements:
56
43
  - - ~>
57
44
  - !ruby/object:Gem::Version
58
- segments:
59
- - 1
60
- - 2
61
- - 0
62
- version: 1.2.0
45
+ version: 1.2.2
63
46
  type: :runtime
47
+ prerelease: false
64
48
  version_requirements: *id003
65
49
  - !ruby/object:Gem::Dependency
66
50
  name: bson_ext
67
- prerelease: false
68
51
  requirement: &id004 !ruby/object:Gem::Requirement
69
52
  none: false
70
53
  requirements:
71
54
  - - ~>
72
55
  - !ruby/object:Gem::Version
73
- segments:
74
- - 1
75
- - 2
76
- - 0
77
- version: 1.2.0
56
+ version: 1.2.2
78
57
  type: :runtime
58
+ prerelease: false
79
59
  version_requirements: *id004
80
60
  - !ruby/object:Gem::Dependency
81
61
  name: tzinfo
82
- prerelease: false
83
62
  requirement: &id005 !ruby/object:Gem::Requirement
84
63
  none: false
85
64
  requirements:
86
65
  - - ~>
87
66
  - !ruby/object:Gem::Version
88
- segments:
89
- - 0
90
- - 3
91
- - 24
92
67
  version: 0.3.24
93
68
  type: :runtime
69
+ prerelease: false
94
70
  version_requirements: *id005
95
71
  - !ruby/object:Gem::Dependency
96
72
  name: jeweler
97
- prerelease: false
98
73
  requirement: &id006 !ruby/object:Gem::Requirement
99
74
  none: false
100
75
  requirements:
101
76
  - - ~>
102
77
  - !ruby/object:Gem::Version
103
- segments:
104
- - 1
105
- - 5
106
- - 2
107
78
  version: 1.5.2
108
79
  type: :development
80
+ prerelease: false
109
81
  version_requirements: *id006
110
82
  - !ruby/object:Gem::Dependency
111
83
  name: yard
112
- prerelease: false
113
84
  requirement: &id007 !ruby/object:Gem::Requirement
114
85
  none: false
115
86
  requirements:
116
87
  - - ~>
117
88
  - !ruby/object:Gem::Version
118
- segments:
119
- - 0
120
- - 6
121
- - 4
122
89
  version: 0.6.4
123
90
  type: :development
91
+ prerelease: false
124
92
  version_requirements: *id007
125
93
  - !ruby/object:Gem::Dependency
126
94
  name: rcov
127
- prerelease: false
128
95
  requirement: &id008 !ruby/object:Gem::Requirement
129
96
  none: false
130
97
  requirements:
131
98
  - - ~>
132
99
  - !ruby/object:Gem::Version
133
- segments:
134
- - 0
135
- - 9
136
- - 9
137
100
  version: 0.9.9
138
101
  type: :development
102
+ prerelease: false
139
103
  version_requirements: *id008
140
104
  - !ruby/object:Gem::Dependency
141
105
  name: rspec
142
- prerelease: false
143
106
  requirement: &id009 !ruby/object:Gem::Requirement
144
107
  none: false
145
108
  requirements:
146
109
  - - "="
147
110
  - !ruby/object:Gem::Version
148
- segments:
149
- - 2
150
- - 4
151
- - 0
152
111
  version: 2.4.0
153
112
  type: :development
113
+ prerelease: false
154
114
  version_requirements: *id009
155
115
  - !ruby/object:Gem::Dependency
156
116
  name: watchr
157
- prerelease: false
158
117
  requirement: &id010 !ruby/object:Gem::Requirement
159
118
  none: false
160
119
  requirements:
161
120
  - - ~>
162
121
  - !ruby/object:Gem::Version
163
- segments:
164
- - 0
165
- - 7
166
122
  version: "0.7"
167
123
  type: :development
124
+ prerelease: false
168
125
  version_requirements: *id010
169
126
  - !ruby/object:Gem::Dependency
170
127
  name: activesupport
171
- prerelease: false
172
128
  requirement: &id011 !ruby/object:Gem::Requirement
173
129
  none: false
174
130
  requirements:
175
131
  - - ~>
176
132
  - !ruby/object:Gem::Version
177
- segments:
178
- - 3
179
- - 0
180
- - 3
181
- version: 3.0.3
133
+ version: 3.0.4
182
134
  type: :runtime
135
+ prerelease: false
183
136
  version_requirements: *id011
184
137
  - !ruby/object:Gem::Dependency
185
138
  name: activemodel
186
- prerelease: false
187
139
  requirement: &id012 !ruby/object:Gem::Requirement
188
140
  none: false
189
141
  requirements:
190
142
  - - ~>
191
143
  - !ruby/object:Gem::Version
192
- segments:
193
- - 3
194
- - 0
195
- - 3
196
- version: 3.0.3
144
+ version: 3.0.4
197
145
  type: :runtime
146
+ prerelease: false
198
147
  version_requirements: *id012
199
148
  - !ruby/object:Gem::Dependency
200
149
  name: mongo
201
- prerelease: false
202
150
  requirement: &id013 !ruby/object:Gem::Requirement
203
151
  none: false
204
152
  requirements:
205
153
  - - ~>
206
154
  - !ruby/object:Gem::Version
207
- segments:
208
- - 1
209
- - 2
210
- - 0
211
- version: 1.2.0
155
+ version: 1.2.2
212
156
  type: :runtime
157
+ prerelease: false
213
158
  version_requirements: *id013
214
159
  - !ruby/object:Gem::Dependency
215
160
  name: bson_ext
216
- prerelease: false
217
161
  requirement: &id014 !ruby/object:Gem::Requirement
218
162
  none: false
219
163
  requirements:
220
164
  - - ~>
221
165
  - !ruby/object:Gem::Version
222
- segments:
223
- - 1
224
- - 2
225
- - 0
226
- version: 1.2.0
166
+ version: 1.2.2
227
167
  type: :runtime
168
+ prerelease: false
228
169
  version_requirements: *id014
229
170
  - !ruby/object:Gem::Dependency
230
171
  name: tzinfo
231
- prerelease: false
232
172
  requirement: &id015 !ruby/object:Gem::Requirement
233
173
  none: false
234
174
  requirements:
235
175
  - - ~>
236
176
  - !ruby/object:Gem::Version
237
- segments:
238
- - 0
239
- - 3
240
- - 24
241
177
  version: 0.3.24
242
178
  type: :runtime
179
+ prerelease: false
243
180
  version_requirements: *id015
244
181
  - !ruby/object:Gem::Dependency
245
182
  name: jeweler
246
- prerelease: false
247
183
  requirement: &id016 !ruby/object:Gem::Requirement
248
184
  none: false
249
185
  requirements:
250
186
  - - ~>
251
187
  - !ruby/object:Gem::Version
252
- segments:
253
- - 1
254
- - 5
255
- - 2
256
188
  version: 1.5.2
257
189
  type: :development
190
+ prerelease: false
258
191
  version_requirements: *id016
259
192
  - !ruby/object:Gem::Dependency
260
193
  name: yard
261
- prerelease: false
262
194
  requirement: &id017 !ruby/object:Gem::Requirement
263
195
  none: false
264
196
  requirements:
265
197
  - - ~>
266
198
  - !ruby/object:Gem::Version
267
- segments:
268
- - 0
269
- - 6
270
- - 4
271
199
  version: 0.6.4
272
200
  type: :development
201
+ prerelease: false
273
202
  version_requirements: *id017
274
203
  - !ruby/object:Gem::Dependency
275
204
  name: rcov
276
- prerelease: false
277
205
  requirement: &id018 !ruby/object:Gem::Requirement
278
206
  none: false
279
207
  requirements:
280
208
  - - ~>
281
209
  - !ruby/object:Gem::Version
282
- segments:
283
- - 0
284
- - 9
285
- - 9
286
210
  version: 0.9.9
287
211
  type: :development
212
+ prerelease: false
288
213
  version_requirements: *id018
289
214
  - !ruby/object:Gem::Dependency
290
215
  name: rspec
291
- prerelease: false
292
216
  requirement: &id019 !ruby/object:Gem::Requirement
293
217
  none: false
294
218
  requirements:
295
219
  - - "="
296
220
  - !ruby/object:Gem::Version
297
- segments:
298
- - 2
299
- - 4
300
- - 0
301
221
  version: 2.4.0
302
222
  type: :development
223
+ prerelease: false
303
224
  version_requirements: *id019
304
225
  - !ruby/object:Gem::Dependency
305
226
  name: watchr
306
- prerelease: false
307
227
  requirement: &id020 !ruby/object:Gem::Requirement
308
228
  none: false
309
229
  requirements:
310
230
  - - ~>
311
231
  - !ruby/object:Gem::Version
312
- segments:
313
- - 0
314
- - 7
315
232
  version: "0.7"
316
233
  type: :development
234
+ prerelease: false
317
235
  version_requirements: *id020
318
236
  description: mongo_odm is a flexible persistence module for any Ruby class to MongoDB.
319
237
  email: carlos@evolve.st
@@ -392,21 +310,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
392
310
  requirements:
393
311
  - - ">="
394
312
  - !ruby/object:Gem::Version
395
- segments:
396
- - 0
397
313
  version: "0"
398
314
  required_rubygems_version: !ruby/object:Gem::Requirement
399
315
  none: false
400
316
  requirements:
401
317
  - - ">="
402
318
  - !ruby/object:Gem::Version
403
- segments:
404
- - 0
405
319
  version: "0"
406
320
  requirements: []
407
321
 
408
322
  rubyforge_project:
409
- rubygems_version: 1.3.7
323
+ rubygems_version: 1.5.2
410
324
  signing_key:
411
325
  specification_version: 3
412
326
  summary: mongo_odm is a flexible persistence module for any Ruby class to MongoDB.