mongoid 2.0.0.beta.15 → 2.0.0.beta.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/lib/config/locales/en.yml +40 -0
  2. data/lib/config/locales/es.yml +41 -0
  3. data/lib/config/locales/fr.yml +42 -0
  4. data/lib/config/locales/it.yml +39 -0
  5. data/lib/config/locales/pl.yml +39 -0
  6. data/lib/config/locales/pt.yml +40 -0
  7. data/lib/config/locales/sv.yml +40 -0
  8. data/lib/mongoid.rb +7 -2
  9. data/lib/mongoid/associations.rb +16 -9
  10. data/lib/mongoid/associations/embedded_in.rb +11 -0
  11. data/lib/mongoid/associations/embeds_many.rb +28 -2
  12. data/lib/mongoid/associations/embeds_one.rb +18 -2
  13. data/lib/mongoid/associations/proxy.rb +28 -1
  14. data/lib/mongoid/associations/referenced_in.rb +10 -0
  15. data/lib/mongoid/associations/references_many.rb +10 -7
  16. data/lib/mongoid/associations/references_many_as_array.rb +29 -0
  17. data/lib/mongoid/associations/references_one.rb +9 -1
  18. data/lib/mongoid/attributes.rb +13 -3
  19. data/lib/mongoid/callbacks.rb +1 -0
  20. data/lib/mongoid/collections.rb +1 -1
  21. data/lib/mongoid/components.rb +1 -0
  22. data/lib/mongoid/config.rb +16 -1
  23. data/lib/mongoid/contexts/enumerable.rb +28 -1
  24. data/lib/mongoid/contexts/enumerable/sort.rb +43 -0
  25. data/lib/mongoid/contexts/mongo.rb +13 -1
  26. data/lib/mongoid/criteria.rb +4 -2
  27. data/lib/mongoid/criterion/inclusion.rb +22 -1
  28. data/lib/mongoid/criterion/optional.rb +14 -39
  29. data/lib/mongoid/criterion/selector.rb +65 -0
  30. data/lib/mongoid/document.rb +5 -11
  31. data/lib/mongoid/errors.rb +10 -130
  32. data/lib/mongoid/errors/document_not_found.rb +29 -0
  33. data/lib/mongoid/errors/invalid_collection.rb +19 -0
  34. data/lib/mongoid/errors/invalid_database.rb +20 -0
  35. data/lib/mongoid/errors/invalid_field.rb +19 -0
  36. data/lib/mongoid/errors/invalid_options.rb +16 -0
  37. data/lib/mongoid/errors/invalid_type.rb +26 -0
  38. data/lib/mongoid/errors/mongoid_error.rb +27 -0
  39. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +21 -0
  40. data/lib/mongoid/errors/unsupported_version.rb +21 -0
  41. data/lib/mongoid/errors/validations.rb +22 -0
  42. data/lib/mongoid/extensions/hash/assimilation.rb +1 -1
  43. data/lib/mongoid/extensions/hash/criteria_helpers.rb +5 -3
  44. data/lib/mongoid/extensions/object/conversions.rb +5 -1
  45. data/lib/mongoid/extensions/objectid/conversions.rb +43 -1
  46. data/lib/mongoid/field.rb +13 -6
  47. data/lib/mongoid/finders.rb +1 -1
  48. data/lib/mongoid/hierarchy.rb +9 -4
  49. data/lib/mongoid/identity.rb +2 -2
  50. data/lib/mongoid/indexes.rb +1 -1
  51. data/lib/mongoid/matchers/default.rb +1 -1
  52. data/lib/mongoid/modifiers.rb +24 -0
  53. data/lib/mongoid/modifiers/command.rb +18 -0
  54. data/lib/mongoid/modifiers/inc.rb +24 -0
  55. data/lib/mongoid/persistence/command.rb +2 -10
  56. data/lib/mongoid/persistence/remove_all.rb +1 -1
  57. data/lib/mongoid/railtie.rb +2 -0
  58. data/lib/mongoid/railties/database.rake +102 -11
  59. data/lib/mongoid/railties/document.rb +12 -0
  60. data/lib/mongoid/safe.rb +13 -0
  61. data/lib/mongoid/safety.rb +12 -0
  62. data/lib/mongoid/validations.rb +0 -4
  63. data/lib/mongoid/version.rb +1 -1
  64. data/lib/mongoid/versioning.rb +11 -1
  65. metadata +55 -28
  66. data/lib/mongoid/validations/locale/en.yml +0 -5
@@ -0,0 +1,12 @@
1
+ module Mongoid
2
+ module Document
3
+ # Used in conjunction with fields_for to build a form element for the
4
+ # destruction of this association. Always returns false because Mongoid
5
+ # only supports immediate deletion of associations.
6
+ #
7
+ # See ActionView::Helpers::FormHelper::fields_for for more info.
8
+ def _destroy
9
+ false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ module Mongoid #:nodoc:
3
+ module Safe #:nodoc:
4
+ # Determine based on configuration if we are persisting in safe mode or
5
+ # not.
6
+ #
7
+ # The query option will always override the global configuration.
8
+ def safe_mode?(options)
9
+ safe = options[:safe]
10
+ safe.nil? ? Mongoid.persist_in_safe_mode : safe
11
+ end
12
+ end
13
+ end
@@ -70,6 +70,18 @@ module Mongoid #:nodoc:
70
70
  @target.send(name, attributes.merge(:safe => true))
71
71
  end
72
72
 
73
+ # Increment the field by the provided value, else if it doesn't exists set
74
+ # it to that value.
75
+ #
76
+ # Options:
77
+ #
78
+ # field: The field to increment.
79
+ # value: The value to increment by.
80
+ # options: Options to pass through to the driver.
81
+ def inc(field, value, options = {})
82
+ @target.inc(field, value, :safe => true)
83
+ end
84
+
73
85
  # Update the +Document+ attributes in the datbase.
74
86
  #
75
87
  # Example:
@@ -2,10 +2,6 @@
2
2
  require "mongoid/validations/associated"
3
3
  require "mongoid/validations/uniqueness"
4
4
 
5
- I18n.load_path << File.join(
6
- File.dirname(__FILE__), "validations", "locale", "en.yml"
7
- )
8
-
9
5
  module Mongoid #:nodoc:
10
6
  # This module provides additional validations that ActiveModel does not
11
7
  # provide: validates_associated and validates_uniqueness_of
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.0.0.beta.15"
3
+ VERSION = "2.0.0.beta.16"
4
4
  end
@@ -5,19 +5,29 @@ module Mongoid #:nodoc:
5
5
  # with all the versions contained in it.
6
6
  module Versioning
7
7
  extend ActiveSupport::Concern
8
+
8
9
  included do
9
10
  field :version, :type => Integer, :default => 1
10
11
  embeds_many :versions, :class_name => self.name
11
12
  set_callback :save, :before, :revise
12
13
  end
13
14
 
15
+ module ClassMethods #:nodoc:
16
+ attr_accessor :version_max
17
+ def max_versions(number)
18
+ self.version_max = number.to_i
19
+ end
20
+ end
21
+
14
22
  # Create a new version of the +Document+. This will load the previous
15
23
  # document from the database and set it as the next version before saving
16
- # the current document. It then increments the version number.
24
+ # the current document. It then increments the version number. If a #max_versions
25
+ # limit is set in the model and it's exceeded, the oldest version gets discarded.
17
26
  def revise
18
27
  last_version = self.class.first(:conditions => { :_id => id, :version => version })
19
28
  if last_version
20
29
  self.versions << last_version.clone
30
+ self.versions.shift if self.class.version_max.present? && self.versions.length > self.class.version_max
21
31
  self.version = version + 1
22
32
  @modifications["versions"] = [ nil, @attributes["versions"] ] if @modifications
23
33
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196477
5
4
  prerelease: true
6
5
  segments:
7
6
  - 2
8
7
  - 0
9
8
  - 0
10
9
  - beta
11
- - 15
12
- version: 2.0.0.beta.15
10
+ - 16
11
+ version: 2.0.0.beta.16
13
12
  platform: ruby
14
13
  authors:
15
14
  - Durran Jordan
@@ -17,18 +16,16 @@ autorequire:
17
16
  bindir: bin
18
17
  cert_chain: []
19
18
 
20
- date: 2010-07-29 00:00:00 -04:00
19
+ date: 2010-08-06 00:00:00 -04:00
21
20
  default_executable:
22
21
  dependencies:
23
22
  - !ruby/object:Gem::Dependency
24
23
  name: activemodel
25
- prerelease: false
26
24
  requirement: &id001 !ruby/object:Gem::Requirement
27
25
  none: false
28
26
  requirements:
29
27
  - - "="
30
28
  - !ruby/object:Gem::Version
31
- hash: 7712042
32
29
  segments:
33
30
  - 3
34
31
  - 0
@@ -36,112 +33,105 @@ dependencies:
36
33
  - rc
37
34
  version: 3.0.0.rc
38
35
  type: :runtime
36
+ prerelease: false
39
37
  version_requirements: *id001
40
38
  - !ruby/object:Gem::Dependency
41
39
  name: tzinfo
42
- prerelease: false
43
40
  requirement: &id002 !ruby/object:Gem::Requirement
44
41
  none: false
45
42
  requirements:
46
43
  - - "="
47
44
  - !ruby/object:Gem::Version
48
- hash: 63
49
45
  segments:
50
46
  - 0
51
47
  - 3
52
48
  - 22
53
49
  version: 0.3.22
54
50
  type: :runtime
51
+ prerelease: false
55
52
  version_requirements: *id002
56
53
  - !ruby/object:Gem::Dependency
57
54
  name: will_paginate
58
- prerelease: false
59
55
  requirement: &id003 !ruby/object:Gem::Requirement
60
56
  none: false
61
57
  requirements:
62
58
  - - ~>
63
59
  - !ruby/object:Gem::Version
64
- hash: 961915916
65
60
  segments:
66
61
  - 3
67
62
  - 0
68
63
  - pre
69
64
  version: 3.0.pre
70
65
  type: :runtime
66
+ prerelease: false
71
67
  version_requirements: *id003
72
68
  - !ruby/object:Gem::Dependency
73
69
  name: mongo
74
- prerelease: false
75
70
  requirement: &id004 !ruby/object:Gem::Requirement
76
71
  none: false
77
72
  requirements:
78
73
  - - "="
79
74
  - !ruby/object:Gem::Version
80
- hash: 27
81
75
  segments:
82
76
  - 1
83
77
  - 0
84
- - 6
85
- version: 1.0.6
78
+ - 7
79
+ version: 1.0.7
86
80
  type: :runtime
81
+ prerelease: false
87
82
  version_requirements: *id004
88
83
  - !ruby/object:Gem::Dependency
89
84
  name: bson
90
- prerelease: false
91
85
  requirement: &id005 !ruby/object:Gem::Requirement
92
86
  none: false
93
87
  requirements:
94
88
  - - "="
95
89
  - !ruby/object:Gem::Version
96
- hash: 31
97
90
  segments:
98
91
  - 1
99
92
  - 0
100
93
  - 4
101
94
  version: 1.0.4
102
95
  type: :runtime
96
+ prerelease: false
103
97
  version_requirements: *id005
104
98
  - !ruby/object:Gem::Dependency
105
99
  name: bson_ext
106
- prerelease: false
107
100
  requirement: &id006 !ruby/object:Gem::Requirement
108
101
  none: false
109
102
  requirements:
110
103
  - - "="
111
104
  - !ruby/object:Gem::Version
112
- hash: 31
113
105
  segments:
114
106
  - 1
115
107
  - 0
116
108
  - 4
117
109
  version: 1.0.4
118
110
  type: :development
111
+ prerelease: false
119
112
  version_requirements: *id006
120
113
  - !ruby/object:Gem::Dependency
121
114
  name: mocha
122
- prerelease: false
123
115
  requirement: &id007 !ruby/object:Gem::Requirement
124
116
  none: false
125
117
  requirements:
126
118
  - - "="
127
119
  - !ruby/object:Gem::Version
128
- hash: 43
129
120
  segments:
130
121
  - 0
131
122
  - 9
132
123
  - 8
133
124
  version: 0.9.8
134
125
  type: :development
126
+ prerelease: false
135
127
  version_requirements: *id007
136
128
  - !ruby/object:Gem::Dependency
137
129
  name: rspec
138
- prerelease: false
139
130
  requirement: &id008 !ruby/object:Gem::Requirement
140
131
  none: false
141
132
  requirements:
142
133
  - - "="
143
134
  - !ruby/object:Gem::Version
144
- hash: 62196421
145
135
  segments:
146
136
  - 2
147
137
  - 0
@@ -150,22 +140,37 @@ dependencies:
150
140
  - 19
151
141
  version: 2.0.0.beta.19
152
142
  type: :development
143
+ prerelease: false
153
144
  version_requirements: *id008
154
145
  - !ruby/object:Gem::Dependency
155
146
  name: watchr
156
- prerelease: false
157
147
  requirement: &id009 !ruby/object:Gem::Requirement
158
148
  none: false
159
149
  requirements:
160
150
  - - "="
161
151
  - !ruby/object:Gem::Version
162
- hash: 7
163
152
  segments:
164
153
  - 0
165
154
  - 6
166
155
  version: "0.6"
167
156
  type: :development
157
+ prerelease: false
168
158
  version_requirements: *id009
159
+ - !ruby/object:Gem::Dependency
160
+ name: ruby-debug-wrapper
161
+ requirement: &id010 !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - "="
165
+ - !ruby/object:Gem::Version
166
+ segments:
167
+ - 0
168
+ - 0
169
+ - 1
170
+ version: 0.0.1
171
+ type: :development
172
+ prerelease: false
173
+ version_requirements: *id010
169
174
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written in Ruby.
170
175
  email:
171
176
  - durran@gmail.com
@@ -176,6 +181,13 @@ extensions: []
176
181
  extra_rdoc_files: []
177
182
 
178
183
  files:
184
+ - lib/config/locales/en.yml
185
+ - lib/config/locales/es.yml
186
+ - lib/config/locales/fr.yml
187
+ - lib/config/locales/it.yml
188
+ - lib/config/locales/pl.yml
189
+ - lib/config/locales/pt.yml
190
+ - lib/config/locales/sv.yml
179
191
  - lib/mongoid/associations/embedded_in.rb
180
192
  - lib/mongoid/associations/embeds_many.rb
181
193
  - lib/mongoid/associations/embeds_one.rb
@@ -199,6 +211,7 @@ files:
199
211
  - lib/mongoid/collections.rb
200
212
  - lib/mongoid/components.rb
201
213
  - lib/mongoid/config.rb
214
+ - lib/mongoid/contexts/enumerable/sort.rb
202
215
  - lib/mongoid/contexts/enumerable.rb
203
216
  - lib/mongoid/contexts/ids.rb
204
217
  - lib/mongoid/contexts/mongo.rb
@@ -209,10 +222,21 @@ files:
209
222
  - lib/mongoid/criterion/exclusion.rb
210
223
  - lib/mongoid/criterion/inclusion.rb
211
224
  - lib/mongoid/criterion/optional.rb
225
+ - lib/mongoid/criterion/selector.rb
212
226
  - lib/mongoid/cursor.rb
213
227
  - lib/mongoid/deprecation.rb
214
228
  - lib/mongoid/dirty.rb
215
229
  - lib/mongoid/document.rb
230
+ - lib/mongoid/errors/document_not_found.rb
231
+ - lib/mongoid/errors/invalid_collection.rb
232
+ - lib/mongoid/errors/invalid_database.rb
233
+ - lib/mongoid/errors/invalid_field.rb
234
+ - lib/mongoid/errors/invalid_options.rb
235
+ - lib/mongoid/errors/invalid_type.rb
236
+ - lib/mongoid/errors/mongoid_error.rb
237
+ - lib/mongoid/errors/too_many_nested_attribute_records.rb
238
+ - lib/mongoid/errors/unsupported_version.rb
239
+ - lib/mongoid/errors/validations.rb
216
240
  - lib/mongoid/errors.rb
217
241
  - lib/mongoid/extensions/array/accessors.rb
218
242
  - lib/mongoid/extensions/array/assimilation.rb
@@ -269,6 +293,9 @@ files:
269
293
  - lib/mongoid/matchers/size.rb
270
294
  - lib/mongoid/matchers.rb
271
295
  - lib/mongoid/memoization.rb
296
+ - lib/mongoid/modifiers/command.rb
297
+ - lib/mongoid/modifiers/inc.rb
298
+ - lib/mongoid/modifiers.rb
272
299
  - lib/mongoid/named_scope.rb
273
300
  - lib/mongoid/paranoia.rb
274
301
  - lib/mongoid/paths.rb
@@ -282,12 +309,13 @@ files:
282
309
  - lib/mongoid/persistence.rb
283
310
  - lib/mongoid/railtie.rb
284
311
  - lib/mongoid/railties/database.rake
312
+ - lib/mongoid/railties/document.rb
313
+ - lib/mongoid/safe.rb
285
314
  - lib/mongoid/safety.rb
286
315
  - lib/mongoid/scope.rb
287
316
  - lib/mongoid/state.rb
288
317
  - lib/mongoid/timestamps.rb
289
318
  - lib/mongoid/validations/associated.rb
290
- - lib/mongoid/validations/locale/en.yml
291
319
  - lib/mongoid/validations/uniqueness.rb
292
320
  - lib/mongoid/validations.rb
293
321
  - lib/mongoid/version.rb
@@ -305,7 +333,7 @@ has_rdoc: true
305
333
  homepage: http://mongoid.org
306
334
  licenses: []
307
335
 
308
- post_install_message: " _________________________________\n |:::::::::::::::::::::::::::::::::| \"I find your lack of faith disturbing.\"\n |:::::::::::::;;::::::::::::::::::|\n |:::::::::::'~||~~~``:::::::::::::| Mongoid 2 introduces\n |::::::::' .': o`:::::::::::| a different way of defining how\n |:::::::' oo | |o o ::::::::::| ids are stored on documents, as\n |::::::: 8 .'.' 8 o :::::::::| well as how foreign key fields\n |::::::: 8 | | 8 :::::::::| and indexes are stored.\n |::::::: _._| |_,...8 :::::::::|\n |::::::'~--. .--. `. `::::::::| If you were using String\n |:::::' =8 ~ \\ o ::::::::| representations of BSON::ObjectIDs\n |::::' 8._ 88. \\ o::::::::| as your document ids, all of your\n |:::' __. ,.ooo~~. \\ o`::::::| documents will now need to tell\n |::: . -. 88`78o/: \\ `:::::| Mongoid to use Strings like so:\n |::' /. o o \\ :: \\88`::::|\n |:; o|| 8 8 |d. `8 `:::| class User\n |:. - ^ ^ -' `-`::| include Mongoid::Document\n |::. .:::| identity :type => String\n |:::::..... ::' ``::| end\n |::::::::-'`- 88 `|\n |:::::-'. - :: | All ids will default to\n |:-~. . . : | BSON:ObjectIDs from now on, and\n | .. . ..: o:8 88o | Config#use_object_ids has been\n |. . ::: 8:P d888. . . | removed.\n |. . :88 88 888' . . |\n | o8 d88P . 88 ' d88P .. | Foreign key fields for relational\n | 88P 888 d8P ' 888 | associations no longer index by\n | 8 d88P.'d:8 .- dP~ o8 | default - you will need to pass\n | 888 888 d~ o888 LS | :index => true to the association\n |_________________________________| definition to have the field indexed\n\n or create the index manually, which is the preferred method. Note that\n if you were using String ids and now want to use object ids instead you\n will have to migrate your database manually - Mongoid cannot perform\n this for you automatically. If you were using custom composite keys,\n these will need to be defined as Strings since they cannot be converted.\n\n Please see the following gist for assistance in migrating the database\n via the Ruby driver (thanks to Kyle Banker):\n\n http://gist.github.com/489098\n\n"
336
+ post_install_message: " _________________________________\n |:::::::::::::::::::::::::::::::::| \"I find your lack of faith disturbing.\"\n |:::::::::::::;;::::::::::::::::::|\n |:::::::::::'~||~~~``:::::::::::::| Mongoid 2 introduces\n |::::::::' .': o`:::::::::::| a different way of defining how\n |:::::::' oo | |o o ::::::::::| ids are stored on documents, as\n |::::::: 8 .'.' 8 o :::::::::| well as how foreign key fields\n |::::::: 8 | | 8 :::::::::| and indexes are stored.\n |::::::: _._| |_,...8 :::::::::|\n |::::::'~--. .--. `. `::::::::| If you were using String\n |:::::' =8 ~ \\ o ::::::::| representations of BSON::ObjectIDs\n |::::' 8._ 88. \\ o::::::::| as your document ids, all of your\n |:::' __. ,.ooo~~. \\ o`::::::| documents will now need to tell\n |::: . -. 88`78o/: \\ `:::::| Mongoid to use Strings like so:\n |::' /. o o \\ :: \\88`::::|\n |:; o|| 8 8 |d. `8 `:::| class User\n |:. - ^ ^ -' `-`::| include Mongoid::Document\n |::. .:::| identity :type => String\n |:::::..... ::' ``::| end\n |::::::::-'`- 88 `|\n |:::::-'. - :: | All ids will default to\n |:-~. . . : | BSON:ObjectIDs from now on, and\n | .. . ..: o:8 88o | Config#use_object_ids has been\n |. . ::: 8:P d888. . . | removed.\n |. . :88 88 888' . . |\n | o8 d88P . 88 ' d88P .. | Foreign key fields for relational\n | 88P 888 d8P ' 888 | associations no longer index by\n | 8 d88P.'d:8 .- dP~ o8 | default - you will need to pass\n | 888 888 d~ o888 LS | :index => true to the association\n |_________________________________| definition to have the field indexed\n\n or create the index manually, which is the preferred method. Note that\n if you were using String ids and now want to use object ids instead you\n will have to migrate your database manually - Mongoid cannot perform\n this for you automatically. If you were using custom composite keys,\n these will need to be defined as Strings since they cannot be converted.\n\n You can run a rake task to convert all your string object ids to ObjectID (thanks to Kyle Banker):\n\n rake db:mongoid:objectid_convert\n\n Your old collections will be backed up to their original names appended with \"_old\".\n If you verify your site is still working good with the ObjectIDs, you can clean them up using:\n\n rake db:mongoid:cleanup_old_collections\n\n"
309
337
  rdoc_options: []
310
338
 
311
339
  require_paths:
@@ -315,7 +343,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
315
343
  requirements:
316
344
  - - ">="
317
345
  - !ruby/object:Gem::Version
318
- hash: 3
346
+ hash: -2440289374354549879
319
347
  segments:
320
348
  - 0
321
349
  version: "0"
@@ -324,7 +352,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
324
352
  requirements:
325
353
  - - ">="
326
354
  - !ruby/object:Gem::Version
327
- hash: 23
328
355
  segments:
329
356
  - 1
330
357
  - 3
@@ -1,5 +0,0 @@
1
- en:
2
- activemodel:
3
- errors:
4
- messages:
5
- taken: "is already taken"