mongoid 3.0.23 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/CHANGELOG.md +253 -9
  2. data/LICENSE +1 -1
  3. data/README.md +4 -1
  4. data/lib/config/locales/en.yml +7 -6
  5. data/lib/mongoid.rb +18 -1
  6. data/lib/mongoid/atomic.rb +22 -20
  7. data/lib/mongoid/atomic/paths/embedded.rb +19 -5
  8. data/lib/mongoid/atomic/paths/root.rb +1 -1
  9. data/lib/mongoid/atomic/positionable.rb +73 -0
  10. data/lib/mongoid/attributes.rb +63 -1
  11. data/lib/mongoid/callbacks.rb +58 -4
  12. data/lib/mongoid/components.rb +8 -3
  13. data/lib/mongoid/config.rb +71 -23
  14. data/lib/mongoid/contextual.rb +2 -1
  15. data/lib/mongoid/contextual/aggregable/mongo.rb +27 -63
  16. data/lib/mongoid/contextual/atomic.rb +4 -3
  17. data/lib/mongoid/contextual/find_and_modify.rb +1 -1
  18. data/lib/mongoid/contextual/geo_near.rb +238 -0
  19. data/lib/mongoid/contextual/map_reduce.rb +12 -1
  20. data/lib/mongoid/contextual/memory.rb +36 -31
  21. data/lib/mongoid/contextual/mongo.rb +147 -91
  22. data/lib/mongoid/contextual/queryable.rb +25 -0
  23. data/lib/mongoid/copyable.rb +4 -1
  24. data/lib/mongoid/criteria.rb +23 -275
  25. data/lib/mongoid/criterion/findable.rb +179 -0
  26. data/lib/mongoid/criterion/modifiable.rb +191 -0
  27. data/lib/mongoid/criterion/scoping.rb +11 -6
  28. data/lib/mongoid/document.rb +7 -56
  29. data/lib/mongoid/equality.rb +66 -0
  30. data/lib/mongoid/errors/mongoid_error.rb +7 -3
  31. data/lib/mongoid/extensions/array.rb +13 -1
  32. data/lib/mongoid/extensions/date.rb +9 -2
  33. data/lib/mongoid/extensions/hash.rb +38 -2
  34. data/lib/mongoid/extensions/nil_class.rb +12 -0
  35. data/lib/mongoid/extensions/object.rb +24 -0
  36. data/lib/mongoid/extensions/string.rb +14 -2
  37. data/lib/mongoid/extensions/time.rb +4 -1
  38. data/lib/mongoid/fields.rb +49 -5
  39. data/lib/mongoid/fields/foreign_key.rb +12 -0
  40. data/lib/mongoid/fields/standard.rb +12 -0
  41. data/lib/mongoid/finders.rb +8 -0
  42. data/lib/mongoid/hierarchy.rb +19 -1
  43. data/lib/mongoid/indexes.rb +30 -4
  44. data/lib/mongoid/indexes/validators/options.rb +12 -2
  45. data/lib/mongoid/inspection.rb +2 -1
  46. data/lib/mongoid/matchers/strategies.rb +5 -5
  47. data/lib/mongoid/observer.rb +27 -36
  48. data/lib/mongoid/persistence.rb +42 -17
  49. data/lib/mongoid/persistence/atomic.rb +10 -5
  50. data/lib/mongoid/persistence/atomic/operation.rb +26 -9
  51. data/lib/mongoid/persistence/atomic/unset.rb +1 -1
  52. data/lib/mongoid/persistence/operations/embedded/insert.rb +5 -2
  53. data/lib/mongoid/persistence/operations/embedded/remove.rb +5 -2
  54. data/lib/mongoid/persistence/operations/update.rb +7 -3
  55. data/lib/mongoid/railties/database.rake +12 -19
  56. data/lib/mongoid/relations.rb +2 -0
  57. data/lib/mongoid/relations/accessors.rb +30 -8
  58. data/lib/mongoid/relations/binding.rb +5 -1
  59. data/lib/mongoid/relations/bindings/referenced/in.rb +1 -1
  60. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +3 -3
  61. data/lib/mongoid/relations/counter_cache.rb +107 -0
  62. data/lib/mongoid/relations/embedded/batchable.rb +13 -4
  63. data/lib/mongoid/relations/embedded/many.rb +30 -1
  64. data/lib/mongoid/relations/macros.rb +2 -0
  65. data/lib/mongoid/relations/marshalable.rb +0 -1
  66. data/lib/mongoid/relations/metadata.rb +63 -11
  67. data/lib/mongoid/relations/options.rb +1 -0
  68. data/lib/mongoid/relations/proxy.rb +45 -2
  69. data/lib/mongoid/relations/referenced/in.rb +11 -2
  70. data/lib/mongoid/relations/referenced/many.rb +31 -3
  71. data/lib/mongoid/relations/referenced/many_to_many.rb +31 -3
  72. data/lib/mongoid/relations/referenced/one.rb +1 -1
  73. data/lib/mongoid/relations/targets/enumerable.rb +5 -1
  74. data/lib/mongoid/relations/touchable.rb +35 -6
  75. data/lib/mongoid/reloading.rb +5 -3
  76. data/lib/mongoid/scoping.rb +2 -2
  77. data/lib/mongoid/sessions.rb +57 -7
  78. data/lib/mongoid/sessions/factory.rb +22 -1
  79. data/lib/mongoid/threaded.rb +4 -30
  80. data/lib/mongoid/threaded/lifecycle.rb +12 -12
  81. data/lib/mongoid/timestamps.rb +1 -0
  82. data/lib/mongoid/timestamps/created.rb +2 -0
  83. data/lib/mongoid/timestamps/created/short.rb +19 -0
  84. data/lib/mongoid/timestamps/short.rb +10 -0
  85. data/lib/mongoid/timestamps/updated.rb +2 -0
  86. data/lib/mongoid/timestamps/updated/short.rb +19 -0
  87. data/lib/mongoid/validations.rb +2 -0
  88. data/lib/mongoid/validations/queryable.rb +2 -2
  89. data/lib/mongoid/validations/uniqueness.rb +1 -18
  90. data/lib/mongoid/version.rb +1 -1
  91. data/lib/rails/generators/mongoid/model/model_generator.rb +1 -0
  92. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +3 -0
  93. data/lib/rails/mongoid.rb +53 -29
  94. data/lib/support/ruby_version.rb +26 -0
  95. metadata +18 -7
@@ -3,23 +3,267 @@
3
3
  For instructions on upgrading to newer versions, visit
4
4
  [mongoid.org](http://mongoid.org/en/mongoid/docs/upgrading.html).
5
5
 
6
- ## 3.0.23
6
+ ## 3.1.0 (branch: master)
7
7
 
8
- ### Resolved Issues
8
+ ### New Features
9
+
10
+ * The minimum MongoDB requirement is now raised to 2.2, since we now
11
+ depend on the aggregation framework.
12
+
13
+ * The minimum Active Model and Active Support dependencies have been
14
+ raised to 3.2.
15
+
16
+ * \#2809 Relations can now specify a primary key to use instead of the
17
+ id on foreign keys.
18
+
19
+ class Person
20
+ include Mongoid::Document
21
+ field :username, type: String
22
+ has_many :cats, primary_key: "username"
23
+ end
24
+
25
+ class Cat
26
+ include Mongoid::Document
27
+ belongs_to :person, primary_key: "username"
28
+ end
29
+
30
+ * \#2804 $geoNear support has now been added to criteria.
31
+
32
+ Bar.where(:likes.gt => 1000).geo_near([ 52, 13 ])
33
+ Bar.geo_near([ 52, 13 ]).max_distance(0.5).spherical
34
+
35
+ * \#2799 Criteria#map can now accept a symbol of a field name as well as
36
+ a block to perform a more optimized `map`. (Gosha Arinich)
37
+
38
+ Band.where(:likes.gt => 1000).map(:name)
39
+
40
+ * \#2798 Aggregations (`sum`, `min`, `max`, `avg`) now use the
41
+ aggregation framework instead of map/reduce. (Gosha Arinich)
42
+
43
+ * \#2776 MongoDB 2.4.x new index types are now supported: "2dsphere",
44
+ "text", and "hashed". (Irakli Janiashvili)
45
+
46
+ * \#2767 $maxScan support from Origin is now supported. (Jonathan Hyman)
47
+
48
+ * \#2701 Cleanup up extra excessive database queries with 1-1 relations.
49
+
50
+ * \#2693 Custom collection names can be passed to the model generator.
51
+ (Subhash Bhushan)
52
+
53
+ rails g model band --collection=artists
54
+
55
+ * \#2688 `Model.create` and `Model.create!` now can take an array of
56
+ attributes hashes to create multiple documents at once. If an array
57
+ of attributes is provided then an array of documents is returned.
58
+
59
+ Band.create([{ name: "Tool" }, { name: "Placebo" }])
60
+ Band.create!([{ name: "Tool" }, { name: "Placebo" }])
61
+
62
+ * \#2670 Unsetting fields now accepts multiple fields instead of only 1.
63
+ (Arthur Neves)
64
+
65
+ band.unset(:name, :founded)
66
+ Band.where(name: "Placebo").unset(:members, :origin)
67
+
68
+ * \#2669 Passing a block to `Criteria#new` now properly sends the
69
+ block through to the model's contructor. (Arthur Neves)
70
+
71
+ * \#2667 `exists?` no longer hits the database in cases where we have
72
+ the necessary information in memory.
73
+
74
+ * \#2665 Mongoid now supports a counter cache for `belongs_to`
75
+ relations. (Arthur Neves)
76
+
77
+ class Band
78
+ include Mongoid::Document
79
+ belongs_to :label, counter_cache: "b_count"
80
+ end
81
+
82
+ class Album
83
+ include Mongoid::Document
84
+ belongs_to :band, counter_cache: true
85
+ end
86
+
87
+ * \#2662 Embedded documents that have `belongs_to` relations may now
88
+ eager load them.
89
+
90
+ * \#2657 Logger getter and setter convenience methods have been
91
+ added to the `Config` module. (Arthur Neves)
92
+
93
+ * \#2615 Index options can now take a specific database name if the
94
+ indexes are only to exist in a database other than the default.
95
+
96
+ class Band
97
+ include Mongoid::Document
98
+ index name: 1, { database: "another_db" }
99
+ end
100
+
101
+ * \#2613 Procs can now be provided as values to `store_in`:
102
+
103
+ class Band
104
+ include Mongoid::Document
105
+ store_in database: ->{ Thread.current[:database] }
106
+ end
107
+
108
+ * \#2609 Pass through batch_size option to query. (Martin Mauch)
109
+
110
+ * \#2555 Passing hashes to `find` when the documents id is of type hash
111
+ now properly works. (Szymon Kurcab)
112
+
113
+ * \#2545 The `$` positional operator is used for update selectors on
114
+ embedded documents that are nested 1 level deep, when appropriate.
115
+
116
+ * \#2539 `Mongoid.models` now tracks all models in the application for more
117
+ accurate determination of models for things such as indexing rake tasks.
118
+ (Ara Howard)
119
+
120
+ * \#2525 Added the ability to have short timestamped fields with aliases. This
121
+ sets timestamp fields as `c_at` and `u_at` that are also aliased as
122
+ `created_at` and `updated_at` for convenience. (Rodrigo Saito)
123
+
124
+ class Band
125
+ include Mongoid::Document
126
+ include Mongoid::Timestamps::Short # For c_at and u_at.
127
+ end
9
128
 
10
- * \#2851 Fixed BigDecimal demongoization of NaN values. (nkem)
129
+ class Band
130
+ include Mongoid::Document
131
+ include Mongoid::Timestamps::Created::Short # For c_at only.
132
+ end
133
+
134
+ class Band
135
+ include Mongoid::Document
136
+ include Mongoid::Timestamps::Updated::Short # For u_at only.
137
+ end
138
+
139
+ * \#2465 Documents now have an `attribute_before_type_cast` for proper
140
+ handling of validations. (Gerad Suyderhoud)
141
+
142
+ * \#2443 `expire_after_seconds` is now a valid index option.
143
+
144
+ class Event
145
+ include Mongoid::Document
146
+ field :status, type: Integer
147
+ index({ status: 1 }, { expire_after_seconds: 3600 })
148
+ end
149
+
150
+ * \#2373 Relations with the `touch: true` option will now be automatically
151
+ touched when the child document is created or destroyed.
152
+
153
+ * Added `Document.first_or_create!` and `Criteria#first_or_create!`. This
154
+ raises a validations error if creation fails validation.
155
+
156
+ Band.where(name: "Depeche Mode").first_or_create!
157
+ Band.where(name: "Tool").first_or_create!(active: true)
11
158
 
12
- * \#2841 Calling `delete_all` or `destroy_all` on an embeds many when in the
13
- middle of a parent update will now properly execute the deletion.
159
+ * Added `Document.first_or_initialize` and `Criteria#first_or_initialize`.
160
+ This is the same as `first_or_create` but initializes a new (unpersisted)
161
+ document if none is found.
162
+
163
+ Band.where(name: "Depeche Mode").first_or_initialize
164
+ Band.where(name: "Tool").first_or_initialize(active: true)
165
+
166
+ * Added `Model.pluck` and `Criteria#pluck` similar to Active Record's, which
167
+ returns an array of values for the provided field. (Jason Lee)
168
+
169
+ Band.where(name: "Depeche Mode").pluck(:_id)
170
+ Band.where(name: "Tool").pluck(:likes)
171
+
172
+ * \#2324 Embeds many relations now properly handle `delete_if`.
173
+
174
+ * \#2317 Added `Document.first_or_create` and `Criteria#first_or_create`.
175
+ This will return the first matching document or create one with additional
176
+ attributes if one does not exist. (incorvia)
177
+
178
+ Band.where(name: "Depeche Mode").first_or_create
179
+ Band.where(name: "Tool").first_or_create(active: true)
180
+
181
+ * \#2292 Added `Model.each_with_index`.
182
+
183
+ * \#2285 `Config.load_configuration` is now public for those who want to instantiate
184
+ settings directly from a hash.
185
+
186
+ * \#2275 Added rake task `db:mongoid:purge` that will drop all collections with
187
+ the exception of the system collections in the default database.
188
+
189
+ * \#2257 `after_find` callbacks have been added for when documents are returned
190
+ from the database.
191
+
192
+ class Band
193
+ include Mongoid::Document
194
+
195
+ after_find do |doc|
196
+ # Some logic here.
197
+ end
198
+ end
199
+
200
+ * \#2223 Allow to find documents by javascript with parameters that are
201
+ protected from javascript injection via `Model.for_js`.
202
+
203
+ Band.for_js("this.name = param", param: "Tool")
204
+ Band.where(:likes.gt => 1000).for_js("this.likes < this.follows")
205
+
206
+ * \#2197 When providing session configuration with no ports, Mongoid will now
207
+ default these to 27017.
208
+
209
+ * \#2180 1-n and n-n relations now support before/after add/remove callbacks.
210
+ (Rodrigo Saito)
211
+
212
+ class Band
213
+ include Mongoid::Document
214
+
215
+ embeds_many :albums, after_add: :notify_labels
216
+ has_many :followers, before_remove: ->(band, follower){ notify_unfollow(follower) }
217
+ end
218
+
219
+ * \#2157 `Criteria#update` and `Criteria#update_all` now serialize values
220
+ according to their field type, if a field is defined.
221
+
222
+ * \#2022 Custom callbacks can now register themselves for use with observers
223
+ by using the `observable` macro.
224
+
225
+ class Band
226
+ include Mongoid::Document
227
+
228
+ define_model_callbacks :notification
229
+ observable :notification
230
+ end
231
+
232
+ class BandObserver < Mongoid::Observer
233
+
234
+ def before_notification(band)
235
+ #...
236
+ end
237
+
238
+ def after_notification(band)
239
+ #...
240
+ end
241
+ end
242
+
243
+ * \#1766 Many to many relations will not touch the database if the foreign key
244
+ is an empty array.
245
+
246
+ * \#1564 Many to many foreign keys now have the default set lazily only if the
247
+ relation has been accessed. This avoids storing empty arrays if the relation
248
+ has not been touched.
249
+
250
+ ### Resolved Issues
251
+
252
+ * \#2730 Calling sort on a context properly updates the context's criteria.
14
253
  (Arthur Neves)
15
254
 
16
- * \#2835 Fixed clearing of persistence options in uniqueness validator.
255
+ * \#2719 `distinct` is now available at the class level.
256
+
257
+ Band.distinct(:name)
17
258
 
18
- * \#2826 Dynamic fields are now properly mongoized.
259
+ * \#2714 Overriding sessions when the new session has a different database will
260
+ now properly switch the database at runtime as well.
19
261
 
20
- * \#2822 Marshal load of relations now properly reapplies extensions.
262
+ * \#2697 Eager loading fixed when including multiple models that inherit from
263
+ the same class. (Kirill Lazarev)
21
264
 
22
- * \#2821 Autosaved relations should be duped in inheriting classes.
265
+ * \#2664 In memory sorting of embedded documents now properly works when
266
+ multiple fields are provided. (Neer Friedman)
23
267
 
24
268
  ## 3.0.22
25
269
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2012 Durran Jordan
1
+ Copyright (c) 2009-2013 Durran Jordan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -8,6 +8,7 @@ Project Tracking
8
8
 
9
9
  * [Mongoid Google Group](http://groups.google.com/group/mongoid)
10
10
  * [Mongoid Website and Documentation](http://mongoid.org)
11
+ * [Mongoid Code Climate](https://codeclimate.com/github/mongoid/mongoid)
11
12
 
12
13
  Compatibility
13
14
  -------------
@@ -23,6 +24,8 @@ Please see the new Mongoid website for up-to-date documentation:
23
24
  Donating
24
25
  --------
25
26
 
27
+ [Support Mongoid at Wepay](https://www.wepay.com/donations/mongoid)
28
+
26
29
  [Support Mongoid at Pledgie](http://www.pledgie.com/campaigns/7757)
27
30
 
28
31
  <a href='http://www.pledgie.com/campaigns/7757'>
@@ -34,7 +37,7 @@ Donating
34
37
  License
35
38
  -------
36
39
 
37
- Copyright (c) 2009-2012 Durran Jordan
40
+ Copyright (c) 2009-2013 Durran Jordan
38
41
 
39
42
  Permission is hereby granted, free of charge, to any person obtaining
40
43
  a copy of this software and associated documentation files (the
@@ -74,7 +74,7 @@ en:
74
74
  resolution: "Remove the invalid option or fix the typo. If you were
75
75
  expecting the option to be there, please consult the following page
76
76
  with repect to Mongoid's configuration:\n\n
77
- \_\_http://mongoid.org/docs/installation.html"
77
+ \_\_http://mongoid.org/en/mongoid/docs/installation.html"
78
78
  invalid_database:
79
79
  message: "Database should be a Mongo::DB, not %{name}."
80
80
  summary: "When setting a master database in the Mongoid configuration
@@ -135,7 +135,8 @@ en:
135
135
  \_\_max: 1\n
136
136
  \_\_bits: 26\n
137
137
  \_\_bucket_size : 1\n
138
- Valid types are: 1, -1, '2d', 'geoHaystack'\n\n
138
+ \_\_weights: { content: 1, title: 2 }\n
139
+ Valid types are: 1, -1, '2d', '2dsphere', 'geoHaystack', 'text', 'hashed'\n\n
139
140
  Example:\n
140
141
  \_\_class Band\n
141
142
  \_\_\_\_include Mongoid::Document\n
@@ -323,8 +324,8 @@ en:
323
324
  message: "Cannot persist embedded document %{klass} without a
324
325
  parent document."
325
326
  summary: "If the document is embedded, in order to be persisted it
326
- must always have a reference to it's parent document. This is
327
- most likely cause by either calling %{klass}.create or
327
+ must always have a reference to its parent document. This is
328
+ most likely caused by either calling %{klass}.create or
328
329
  %{klass}.create! without setting the parent document as an
329
330
  attribute."
330
331
  resolution: "Ensure that you've set the parent relation if
@@ -393,7 +394,7 @@ en:
393
394
  summary: "Attributes flagged as readonly via Model.attr_readonly
394
395
  can only have values set when the document is a new record."
395
396
  resolution: "Don't define '%{name}' as readonly, or do not attempt
396
- to update it's value after the document is persisted."
397
+ to update its value after the document is persisted."
397
398
  scope_overwrite:
398
399
  message: "Cannot create scope :%{scope_name}, because of existing
399
400
  method %{model_name}.%{scope_name}."
@@ -403,7 +404,7 @@ en:
403
404
  resolution: "Change the name of the scope so it does not conflict
404
405
  with the already defined method %{model_name}, or set the
405
406
  configuration option Mongoid.scope_overwrite_exception to false,
406
- which is it's default. In this case a warning will be logged."
407
+ which is its default. In this case a warning will be logged."
407
408
  taken:
408
409
  "is already taken"
409
410
  too_many_nested_attribute_records:
@@ -20,6 +20,9 @@
20
20
  # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ require 'support/ruby_version'
25
+
23
26
  require "delegate"
24
27
  require "time"
25
28
  require "set"
@@ -33,6 +36,7 @@ require "active_model"
33
36
  require "origin"
34
37
  require "moped"
35
38
 
39
+ require "mongoid/atomic/positionable"
36
40
  require "mongoid/evolvable"
37
41
  require "mongoid/extensions"
38
42
  require "mongoid/errors"
@@ -44,6 +48,7 @@ require "mongoid/callbacks"
44
48
  require "mongoid/config"
45
49
  require "mongoid/contextual"
46
50
  require "mongoid/copyable"
51
+ require "mongoid/equality"
47
52
  require "mongoid/criteria"
48
53
  require "mongoid/dirty"
49
54
  require "mongoid/factory"
@@ -124,6 +129,18 @@ module Mongoid
124
129
  Sessions.default
125
130
  end
126
131
 
132
+ # Disconnect all active sessions.
133
+ #
134
+ # @example Disconnect all active sessions.
135
+ # Mongoid.disconnect_sessions
136
+ #
137
+ # @return [ true ] True.
138
+ #
139
+ # @since 3.1.0
140
+ def disconnect_sessions
141
+ Sessions.disconnect
142
+ end
143
+
127
144
  # Convenience method for getting a named session.
128
145
  #
129
146
  # @example Get a named session.
@@ -144,6 +161,6 @@ module Mongoid
144
161
  #
145
162
  # @since 1.0.0
146
163
  delegate(*(Config.public_instance_methods(false) +
147
- ActiveModel::Observing::ClassMethods.public_instance_methods(false) <<
164
+ ActiveModel::Observing::ClassMethods.public_instance_methods(false) - [:logger=, :logger] <<
148
165
  { to: Config }))
149
166
  end
@@ -54,6 +54,18 @@ module Mongoid
54
54
  (delayed_atomic_unsets[document.metadata_name.to_s] ||= []).push(document)
55
55
  end
56
56
 
57
+ # Returns path of the attribute for modification
58
+ #
59
+ # @example Get path of the attribute
60
+ # address.atomic_attribute_name(:city)
61
+ #
62
+ # @return [ String ] The path to the document attribute in the database
63
+ #
64
+ # @since 3.0.0
65
+ def atomic_attribute_name(name)
66
+ embedded? ? "#{atomic_position}.#{name}" : name
67
+ end
68
+
57
69
  # For array fields these are the pushes that need to happen.
58
70
  #
59
71
  # @example Get the array pushes.
@@ -113,7 +125,7 @@ module Mongoid
113
125
  # @return [ Hash ] The updates and their modifiers.
114
126
  #
115
127
  # @since 2.1.0
116
- def atomic_updates
128
+ def atomic_updates(use_indexes = false)
117
129
  process_flagged_destroys
118
130
  mods = Modifiers.new
119
131
  generate_atomic_updates(mods, self)
@@ -168,14 +180,16 @@ module Mongoid
168
180
  atomic_paths.position
169
181
  end
170
182
 
171
- # Returns path of the attribute for modification
183
+ # Get the atomic paths utility for this document.
172
184
  #
173
- # @example Get path of the attribute
174
- # address.atomic_attribute_name(:city)
185
+ # @example Get the atomic paths.
186
+ # document.atomic_paths
175
187
  #
176
- # @return [ String ] The path to the document attribute in the database
177
- def atomic_attribute_name(name)
178
- embedded? ? "#{atomic_position}.#{name}" : name
188
+ # @return [ Object ] The associated path.
189
+ #
190
+ # @since 2.1.0
191
+ def atomic_paths
192
+ @atomic_paths ||= metadata ? metadata.path(self) : Atomic::Paths::Root.new(self)
179
193
  end
180
194
 
181
195
  # Get all the attributes that need to be pulled.
@@ -208,7 +222,7 @@ module Mongoid
208
222
  #
209
223
  # @since 2.1.0
210
224
  def atomic_pushes
211
- pushable? ? { atomic_path => as_document } : {}
225
+ pushable? ? { atomic_position => as_document } : {}
212
226
  end
213
227
 
214
228
  # Return the selector for this document to be matched exactly for use
@@ -335,18 +349,6 @@ module Mongoid
335
349
 
336
350
  private
337
351
 
338
- # Get the atomic paths utility for this document.
339
- #
340
- # @example Get the atomic paths.
341
- # document.atomic_paths
342
- #
343
- # @return [ Object ] The associated path.
344
- #
345
- # @since 2.1.0
346
- def atomic_paths
347
- @atomic_paths ||= metadata ? metadata.path(self) : Atomic::Paths::Root.new(self)
348
- end
349
-
350
352
  # Generates the atomic updates in the correct order.
351
353
  #
352
354
  # @example Generate the updates.