mongoid 3.0.0.rc → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/CHANGELOG.md +109 -4
  2. data/README.md +1 -1
  3. data/Rakefile +1 -0
  4. data/lib/config/locales/en.yml +15 -1
  5. data/lib/mongoid.rb +17 -2
  6. data/lib/mongoid/atomic.rb +54 -7
  7. data/lib/mongoid/attributes.rb +1 -1
  8. data/lib/mongoid/attributes/processing.rb +1 -1
  9. data/lib/mongoid/callbacks.rb +6 -1
  10. data/lib/mongoid/components.rb +2 -1
  11. data/lib/mongoid/config.rb +42 -17
  12. data/lib/mongoid/config/environment.rb +3 -1
  13. data/lib/mongoid/contextual/aggregable/memory.rb +21 -10
  14. data/lib/mongoid/contextual/find_and_modify.rb +14 -12
  15. data/lib/mongoid/contextual/memory.rb +24 -1
  16. data/lib/mongoid/contextual/mongo.rb +148 -29
  17. data/lib/mongoid/copyable.rb +6 -24
  18. data/lib/mongoid/criteria.rb +116 -34
  19. data/lib/mongoid/document.rb +7 -7
  20. data/lib/mongoid/errors.rb +1 -0
  21. data/lib/mongoid/errors/no_metadata.rb +21 -0
  22. data/lib/mongoid/evolvable.rb +19 -0
  23. data/lib/mongoid/extensions.rb +1 -1
  24. data/lib/mongoid/extensions/array.rb +38 -1
  25. data/lib/mongoid/extensions/big_decimal.rb +1 -1
  26. data/lib/mongoid/extensions/date_time.rb +6 -1
  27. data/lib/mongoid/extensions/false_class.rb +12 -0
  28. data/lib/mongoid/extensions/float.rb +12 -0
  29. data/lib/mongoid/extensions/hash.rb +33 -1
  30. data/lib/mongoid/extensions/integer.rb +12 -0
  31. data/lib/mongoid/extensions/object.rb +51 -1
  32. data/lib/mongoid/extensions/object_id.rb +2 -1
  33. data/lib/mongoid/extensions/range.rb +24 -0
  34. data/lib/mongoid/extensions/string.rb +31 -5
  35. data/lib/mongoid/extensions/true_class.rb +12 -0
  36. data/lib/mongoid/fields.rb +20 -21
  37. data/lib/mongoid/fields/foreign_key.rb +23 -7
  38. data/lib/mongoid/fields/standard.rb +3 -3
  39. data/lib/mongoid/finders.rb +3 -7
  40. data/lib/mongoid/hierarchy.rb +19 -1
  41. data/lib/mongoid/identity_map.rb +20 -4
  42. data/lib/mongoid/indexes/validators/options.rb +1 -1
  43. data/lib/mongoid/multi_parameter_attributes.rb +1 -1
  44. data/lib/mongoid/paranoia.rb +3 -32
  45. data/lib/mongoid/persistence.rb +33 -15
  46. data/lib/mongoid/persistence/atomic/operation.rb +1 -1
  47. data/lib/mongoid/persistence/operations.rb +16 -0
  48. data/lib/mongoid/persistence/operations/remove.rb +1 -1
  49. data/lib/mongoid/persistence/operations/upsert.rb +28 -0
  50. data/lib/mongoid/persistence/upsertion.rb +30 -0
  51. data/lib/mongoid/relations.rb +16 -0
  52. data/lib/mongoid/relations/accessors.rb +1 -1
  53. data/lib/mongoid/relations/bindings/referenced/in.rb +1 -1
  54. data/lib/mongoid/relations/builder.rb +1 -1
  55. data/lib/mongoid/relations/builders/nested_attributes/one.rb +1 -1
  56. data/lib/mongoid/relations/builders/referenced/many.rb +1 -1
  57. data/lib/mongoid/relations/cascading.rb +4 -3
  58. data/lib/mongoid/relations/constraint.rb +1 -1
  59. data/lib/mongoid/relations/conversions.rb +1 -1
  60. data/lib/mongoid/relations/embedded/batchable.rb +3 -2
  61. data/lib/mongoid/relations/embedded/many.rb +4 -4
  62. data/lib/mongoid/relations/embedded/one.rb +1 -1
  63. data/lib/mongoid/relations/metadata.rb +67 -23
  64. data/lib/mongoid/relations/nested_builder.rb +2 -2
  65. data/lib/mongoid/relations/proxy.rb +9 -7
  66. data/lib/mongoid/relations/referenced/many.rb +69 -25
  67. data/lib/mongoid/relations/referenced/many_to_many.rb +14 -13
  68. data/lib/mongoid/scoping.rb +0 -17
  69. data/lib/mongoid/serialization.rb +95 -26
  70. data/lib/mongoid/sessions.rb +30 -6
  71. data/lib/mongoid/sessions/factory.rb +2 -0
  72. data/lib/mongoid/threaded.rb +52 -0
  73. data/lib/mongoid/timestamps/created.rb +1 -1
  74. data/lib/mongoid/timestamps/updated.rb +2 -1
  75. data/lib/mongoid/validations/uniqueness.rb +3 -2
  76. data/lib/mongoid/version.rb +1 -1
  77. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +8 -0
  78. data/lib/rails/mongoid.rb +8 -5
  79. metadata +30 -13
  80. data/lib/mongoid/collections/retry.rb +0 -58
  81. data/lib/mongoid/javascript.rb +0 -20
  82. data/lib/mongoid/javascript/functions.yml +0 -63
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc
5
- prerelease: 6
4
+ version: 3.0.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Durran Jordan
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-28 00:00:00.000000000 Z
12
+ date: 2012-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 1.0.0.rc
53
+ version: 1.1.1
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 1.0.0.rc
61
+ version: 1.1.1
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: origin
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 1.0.0.rc
69
+ version: 1.0.3
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,13 +74,13 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 1.0.0.rc
77
+ version: 1.0.3
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: mocha
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ~>
83
+ - - '='
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0.11'
86
86
  type: :development
@@ -88,7 +88,7 @@ dependencies:
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - ~>
91
+ - - '='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0.11'
94
94
  - !ruby/object:Gem::Dependency
@@ -107,6 +107,22 @@ dependencies:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
109
  version: '2.10'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.2.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - '='
124
+ - !ruby/object:Gem::Version
125
+ version: 1.2.1
110
126
  - !ruby/object:Gem::Dependency
111
127
  name: guard-rspec
112
128
  requirement: !ruby/object:Gem::Requirement
@@ -143,7 +159,6 @@ files:
143
159
  - lib/mongoid/attributes/readonly.rb
144
160
  - lib/mongoid/attributes.rb
145
161
  - lib/mongoid/callbacks.rb
146
- - lib/mongoid/collections/retry.rb
147
162
  - lib/mongoid/components.rb
148
163
  - lib/mongoid/config/environment.rb
149
164
  - lib/mongoid/config/inflections.rb
@@ -192,6 +207,7 @@ files:
192
207
  - lib/mongoid/errors/no_default_session.rb
193
208
  - lib/mongoid/errors/no_environment.rb
194
209
  - lib/mongoid/errors/no_map_reduce_output.rb
210
+ - lib/mongoid/errors/no_metadata.rb
195
211
  - lib/mongoid/errors/no_parent.rb
196
212
  - lib/mongoid/errors/no_session_config.rb
197
213
  - lib/mongoid/errors/no_session_database.rb
@@ -207,6 +223,7 @@ files:
207
223
  - lib/mongoid/errors/validations.rb
208
224
  - lib/mongoid/errors/versioning_not_on_root.rb
209
225
  - lib/mongoid/errors.rb
226
+ - lib/mongoid/evolvable.rb
210
227
  - lib/mongoid/extensions/array.rb
211
228
  - lib/mongoid/extensions/big_decimal.rb
212
229
  - lib/mongoid/extensions/boolean.rb
@@ -242,8 +259,6 @@ files:
242
259
  - lib/mongoid/indexes/validators/options.rb
243
260
  - lib/mongoid/indexes.rb
244
261
  - lib/mongoid/inspection.rb
245
- - lib/mongoid/javascript/functions.yml
246
- - lib/mongoid/javascript.rb
247
262
  - lib/mongoid/json.rb
248
263
  - lib/mongoid/loggable.rb
249
264
  - lib/mongoid/matchers/all.rb
@@ -286,7 +301,9 @@ files:
286
301
  - lib/mongoid/persistence/operations/insert.rb
287
302
  - lib/mongoid/persistence/operations/remove.rb
288
303
  - lib/mongoid/persistence/operations/update.rb
304
+ - lib/mongoid/persistence/operations/upsert.rb
289
305
  - lib/mongoid/persistence/operations.rb
306
+ - lib/mongoid/persistence/upsertion.rb
290
307
  - lib/mongoid/persistence.rb
291
308
  - lib/mongoid/railtie.rb
292
309
  - lib/mongoid/railties/database.rake
@@ -399,7 +416,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
399
416
  version: '0'
400
417
  segments:
401
418
  - 0
402
- hash: 2284933859052458151
419
+ hash: 1324901210162009503
403
420
  required_rubygems_version: !ruby/object:Gem::Requirement
404
421
  none: false
405
422
  requirements:
@@ -1,58 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid
3
- module Collections
4
-
5
- # Provides behaviour for retrying commands on connection failure.
6
- module Retry
7
-
8
- # Retries command on connection failures.
9
- #
10
- # This is useful when using replica sets. When a primary server wents
11
- # down and a command is issued, the driver will raise a
12
- # Mongo::ConnectionFailure. We wait a little bit, because nodes are
13
- # electing themselves, and then retry the given command.
14
- #
15
- # By setting Mongoid.max_retries_on_connection_failure to a value of 0,
16
- # no attempt will be made, immediately raising connection failure.
17
- # Otherwise it will attempt to make the specified number of retries
18
- # and then raising the exception to clients.
19
- #
20
- # @example Retry the command.
21
- # retry_on_connection_failure do
22
- # collection.send(name, *args)
23
- # end
24
- #
25
- # @since 2.0.0
26
- def retry_on_connection_failure
27
- retries = 0
28
- begin
29
- yield
30
- rescue Mongo::ConnectionFailure => ex
31
- retries = increase_retry_attempts(retries, ex)
32
- retry
33
- rescue Mongo::OperationFailure => ex
34
- if ex.message =~ /not master/
35
- retries = increase_retry_attempts(retries, ex)
36
- retry
37
- else
38
- raise ex
39
- end
40
- end
41
- end
42
-
43
- private
44
-
45
- def increase_retry_attempts(retries, ex)
46
- retries += 1
47
- raise ex if retries > Mongoid.max_retries_on_connection_failure
48
- Kernel.sleep(0.5)
49
- log_retry retries, ex
50
- retries
51
- end
52
-
53
- def log_retry(retry_number, ex)
54
- Mongoid.logger.warn "A #{ex.class.name} was raised. Retry attempt ##{retry_number}." if Mongoid.logger
55
- end
56
- end
57
- end
58
- end
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid
3
- class Javascript
4
- # Constant for the file that defines all the js functions.
5
- FUNCTIONS = File.join(File.dirname(__FILE__), "javascript", "functions.yml")
6
-
7
- # Load the javascript functions and define a class method for each one,
8
- # that memoizes the value.
9
- #
10
- # @example Get the function.
11
- # Mongoid::Javascript.aggregate
12
- YAML.load(File.read(FUNCTIONS)).each_pair do |key, function|
13
- (class << self; self; end).class_eval <<-EOT
14
- def #{key}
15
- @#{key} ||= "#{function}"
16
- end
17
- EOT
18
- end
19
- end
20
- end
@@ -1,63 +0,0 @@
1
- aggregate:
2
- "function(obj, prev) {
3
- prev.count++;
4
- }"
5
-
6
- group:
7
- "function(obj, prev) {
8
- prev.group.push(obj);
9
- }"
10
-
11
- max:
12
- "function(obj, prev) {
13
- if (obj.[field] && prev.max == 'start') {
14
- prev.max = obj.[field];
15
- }
16
- if (obj.[field] && prev.max < obj.[field]) {
17
- prev.max = obj.[field];
18
- }
19
- }"
20
-
21
- max_finalize:
22
- "function(obj) {
23
- if (obj.max == 'start' || isNaN(obj.max)) {
24
- obj.max = 0;
25
- }
26
- return obj;
27
- }"
28
-
29
- min:
30
- "function(obj, prev) {
31
- if (obj.[field] && prev.min == 'start') {
32
- prev.min = obj.[field];
33
- }
34
- if (obj.[field] && prev.min > obj.[field]) {
35
- prev.min = obj.[field];
36
- }
37
- }"
38
-
39
- min_finalize:
40
- "function(obj) {
41
- if (obj.min == 'start' || isNaN(obj.min)) {
42
- obj.min = 0;
43
- }
44
- return obj;
45
- }"
46
-
47
- sum:
48
- "function(obj, prev) {
49
- if (prev.sum == 'start') {
50
- prev.sum = 0;
51
- }
52
- if (obj.[field]) {
53
- prev.sum += obj.[field];
54
- }
55
- }"
56
-
57
- sum_finalize:
58
- "function(obj) {
59
- if (obj.sum == 'start' || isNaN(obj.sum)) {
60
- obj.sum = 0;
61
- }
62
- return obj;
63
- }"