mongoid 2.1.7 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -1
- data/lib/config/locales/en.yml +1 -1
- data/lib/mongoid/attributes.rb +6 -5
- data/lib/mongoid/collection.rb +4 -4
- data/lib/mongoid/collections.rb +2 -2
- data/lib/mongoid/components.rb +48 -0
- data/lib/mongoid/config.rb +1 -7
- data/lib/mongoid/contexts/enumerable.rb +8 -1
- data/lib/mongoid/extras.rb +2 -1
- data/lib/mongoid/fields.rb +36 -14
- data/lib/mongoid/fields/serializable.rb +21 -18
- data/lib/mongoid/fields/serializable/array.rb +0 -14
- data/lib/mongoid/fields/serializable/foreign_keys/array.rb +0 -13
- data/lib/mongoid/fields/serializable/hash.rb +0 -14
- data/lib/mongoid/fields/serializable/nil_class.rb +38 -0
- data/lib/mongoid/identity.rb +2 -4
- data/lib/mongoid/keys.rb +3 -3
- data/lib/mongoid/nested_attributes.rb +2 -2
- data/lib/mongoid/railtie.rb +0 -14
- data/lib/mongoid/relations/embedded/atomic.rb +3 -2
- data/lib/mongoid/relations/macros.rb +4 -4
- data/lib/mongoid/relations/one.rb +14 -0
- data/lib/mongoid/relations/proxy.rb +12 -0
- data/lib/mongoid/relations/referenced/in.rb +1 -1
- data/lib/mongoid/relations/referenced/one.rb +1 -0
- data/lib/mongoid/relations/reflections.rb +3 -6
- data/lib/mongoid/sharding.rb +2 -2
- data/lib/mongoid/threaded.rb +4 -4
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/versioning.rb +2 -1
- metadata +20 -19
data/README.rdoc
CHANGED
@@ -13,7 +13,7 @@ Mongoid is an ODM (Object-Document-Mapper) framework for MongoDB in Ruby.
|
|
13
13
|
|
14
14
|
Mongoid is tested against Ruby 1.8.7, 1.9.2, 1.9.3, REE, Rubinius, and JRuby.
|
15
15
|
|
16
|
-
|
16
|
+
https://secure.travis-ci.org/mongoid/mongoid.png?branch=master&.png {Build History}[http://travis-ci.org/mongoid/mongoid]
|
17
17
|
|
18
18
|
= Documentation
|
19
19
|
|
data/lib/config/locales/en.yml
CHANGED
@@ -26,7 +26,7 @@ en:
|
|
26
26
|
invalid_field:
|
27
27
|
Defining a field named %{name} is not allowed. Do not define
|
28
28
|
fields that conflict with Mongoid internal attributes or method
|
29
|
-
names. Use
|
29
|
+
names. Use Mongoid.destructive_fields to see what names this includes.
|
30
30
|
too_many_nested_attribute_records:
|
31
31
|
Accepting nested attributes for %{association} is limited
|
32
32
|
to %{limit} records.
|
data/lib/mongoid/attributes.rb
CHANGED
@@ -134,11 +134,12 @@ module Mongoid #:nodoc:
|
|
134
134
|
#
|
135
135
|
# @since 2.0.0.rc.8
|
136
136
|
def apply_default_attributes
|
137
|
-
(@attributes ||= {}).tap do |
|
138
|
-
defaults.
|
139
|
-
unless
|
140
|
-
|
141
|
-
|
137
|
+
(@attributes ||= {}).tap do |attrs|
|
138
|
+
defaults.each do |name|
|
139
|
+
unless attrs.has_key?(name)
|
140
|
+
if field = fields[name]
|
141
|
+
attrs[name] = field.eval_default(self)
|
142
|
+
end
|
142
143
|
end
|
143
144
|
end
|
144
145
|
end
|
data/lib/mongoid/collection.rb
CHANGED
@@ -8,7 +8,7 @@ module Mongoid #:nodoc
|
|
8
8
|
# This class is the Mongoid wrapper to the Mongo Ruby driver's collection
|
9
9
|
# object.
|
10
10
|
class Collection
|
11
|
-
attr_reader :counter, :name
|
11
|
+
attr_reader :counter, :klass, :name
|
12
12
|
|
13
13
|
# All write operations should delegate to the master connection. These
|
14
14
|
# operations mimic the methods on a Mongo:Collection.
|
@@ -27,7 +27,7 @@ module Mongoid #:nodoc
|
|
27
27
|
#
|
28
28
|
# @return [ Cursor ] The results.
|
29
29
|
def find(selector = {}, options = {})
|
30
|
-
cursor = Mongoid::Cursor.new(
|
30
|
+
cursor = Mongoid::Cursor.new(klass, self, master(options).find(selector, options))
|
31
31
|
if block_given?
|
32
32
|
yield cursor; cursor.close
|
33
33
|
else
|
@@ -105,7 +105,7 @@ module Mongoid #:nodoc
|
|
105
105
|
# @return [ Master ] The master connection.
|
106
106
|
def master(options = {})
|
107
107
|
options.delete(:cache)
|
108
|
-
db = Mongoid.databases[
|
108
|
+
db = Mongoid.databases[klass.database] || Mongoid.master
|
109
109
|
@master ||= Collections::Master.new(db, @name)
|
110
110
|
end
|
111
111
|
|
@@ -124,7 +124,7 @@ module Mongoid #:nodoc
|
|
124
124
|
#
|
125
125
|
# @since 2.0.0
|
126
126
|
def update(selector, document, options = {})
|
127
|
-
updater = Threaded.
|
127
|
+
updater = Threaded.update_consumer(klass)
|
128
128
|
if updater
|
129
129
|
updater.consume(selector, document, options)
|
130
130
|
else
|
data/lib/mongoid/collections.rb
CHANGED
@@ -6,11 +6,11 @@ module Mongoid #:nodoc
|
|
6
6
|
module Collections
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
|
+
delegate :collection, :db, :to => "self.class"
|
10
|
+
|
9
11
|
included do
|
10
12
|
cattr_accessor :_collection, :collection_name
|
11
13
|
self.collection_name = self.name.collectionize
|
12
|
-
|
13
|
-
delegate :collection, :db, :to => "self.class"
|
14
14
|
end
|
15
15
|
|
16
16
|
module ClassMethods #:nodoc:
|
data/lib/mongoid/components.rb
CHANGED
@@ -41,5 +41,53 @@ module Mongoid #:nodoc
|
|
41
41
|
include Mongoid::Validations
|
42
42
|
include Mongoid::Callbacks
|
43
43
|
include Mongoid::MultiDatabase
|
44
|
+
|
45
|
+
MODULES = [
|
46
|
+
Mongoid::Atomic,
|
47
|
+
Mongoid::Attributes,
|
48
|
+
Mongoid::Collections,
|
49
|
+
Mongoid::Copyable,
|
50
|
+
Mongoid::DefaultScope,
|
51
|
+
Mongoid::Dirty,
|
52
|
+
Mongoid::Extras,
|
53
|
+
Mongoid::Fields,
|
54
|
+
Mongoid::Hierarchy,
|
55
|
+
Mongoid::Indexes,
|
56
|
+
Mongoid::Inspection,
|
57
|
+
Mongoid::JSON,
|
58
|
+
Mongoid::Keys,
|
59
|
+
Mongoid::Matchers,
|
60
|
+
Mongoid::NamedScope,
|
61
|
+
Mongoid::NestedAttributes,
|
62
|
+
Mongoid::Persistence,
|
63
|
+
Mongoid::Relations,
|
64
|
+
Mongoid::Safety,
|
65
|
+
Mongoid::Serialization,
|
66
|
+
Mongoid::Sharding,
|
67
|
+
Mongoid::State,
|
68
|
+
Mongoid::Validations,
|
69
|
+
Mongoid::Callbacks,
|
70
|
+
Mongoid::MultiDatabase,
|
71
|
+
]
|
72
|
+
|
73
|
+
class << self
|
74
|
+
|
75
|
+
# Get a list of methods that would be a bad idea to define as field names
|
76
|
+
# or override when including Mongoid::Document.
|
77
|
+
#
|
78
|
+
# @example Bad thing!
|
79
|
+
# Mongoid::Components.prohibited_methods
|
80
|
+
#
|
81
|
+
# @return [ Array<Symbol> ]
|
82
|
+
#
|
83
|
+
# @since 2.1.8
|
84
|
+
def prohibited_methods
|
85
|
+
@prohibited_methods ||= MODULES.inject([]) do |methods, mod|
|
86
|
+
methods.tap do |mets|
|
87
|
+
mets << mod.instance_methods.map{ |m| m.to_sym }
|
88
|
+
end
|
89
|
+
end.flatten
|
90
|
+
end
|
91
|
+
end
|
44
92
|
end
|
45
93
|
end
|
data/lib/mongoid/config.rb
CHANGED
@@ -49,7 +49,6 @@ module Mongoid #:nodoc
|
|
49
49
|
option :allow_dynamic_fields, :default => true
|
50
50
|
option :autocreate_indexes, :default => false
|
51
51
|
option :binding_defaults, :default => { :binding => false, :continue => true }
|
52
|
-
option :embedded_object_id, :default => true
|
53
52
|
option :identity_map_enabled, :default => false
|
54
53
|
option :include_root_in_json, :default => false
|
55
54
|
option :max_retries_on_connection_failure, :default => 0
|
@@ -104,12 +103,7 @@ module Mongoid #:nodoc
|
|
104
103
|
#
|
105
104
|
# @return [ Array<String> ] An array of bad field names.
|
106
105
|
def destructive_fields
|
107
|
-
|
108
|
-
klass = Class.new do
|
109
|
-
include Mongoid::Document
|
110
|
-
end
|
111
|
-
klass.instance_methods(true).collect { |method| method.to_s }
|
112
|
-
}.call
|
106
|
+
Components.prohibited_methods
|
113
107
|
end
|
114
108
|
|
115
109
|
# Configure mongoid from a hash. This is usually called after parsing a
|
@@ -251,6 +251,14 @@ module Mongoid #:nodoc:
|
|
251
251
|
documents
|
252
252
|
end
|
253
253
|
|
254
|
+
def root
|
255
|
+
@root ||= documents.first.try(:_root)
|
256
|
+
end
|
257
|
+
|
258
|
+
def root_class
|
259
|
+
@root_class ||= root ? root.class : nil
|
260
|
+
end
|
261
|
+
|
254
262
|
# Set the collection to the collection of the root document.
|
255
263
|
#
|
256
264
|
# @example Set the collection.
|
@@ -258,7 +266,6 @@ module Mongoid #:nodoc:
|
|
258
266
|
#
|
259
267
|
# @return [ Collection ] The root collection.
|
260
268
|
def set_collection
|
261
|
-
root = documents.first.try(:_root)
|
262
269
|
@collection = root.collection if root && !root.embedded?
|
263
270
|
end
|
264
271
|
|
data/lib/mongoid/extras.rb
CHANGED
@@ -5,10 +5,11 @@ module Mongoid #:nodoc:
|
|
5
5
|
module Extras
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
+
delegate :cached?, :to => "self.class"
|
9
|
+
|
8
10
|
included do
|
9
11
|
class_attribute :cached
|
10
12
|
self.cached = false
|
11
|
-
delegate :cached?, :to => "self.class"
|
12
13
|
end
|
13
14
|
|
14
15
|
module ClassMethods #:nodoc
|
data/lib/mongoid/fields.rb
CHANGED
@@ -13,6 +13,7 @@ require "mongoid/fields/serializable/hash"
|
|
13
13
|
require "mongoid/fields/serializable/integer"
|
14
14
|
require "mongoid/fields/serializable/bignum"
|
15
15
|
require "mongoid/fields/serializable/fixnum"
|
16
|
+
require "mongoid/fields/serializable/nil_class"
|
16
17
|
require "mongoid/fields/serializable/object"
|
17
18
|
require "mongoid/fields/serializable/object_id"
|
18
19
|
require "mongoid/fields/serializable/range"
|
@@ -30,11 +31,9 @@ module Mongoid #:nodoc
|
|
30
31
|
module Fields
|
31
32
|
extend ActiveSupport::Concern
|
32
33
|
|
33
|
-
|
34
|
-
# Set up the class attributes that must be available to all subclasses.
|
35
|
-
# These include defaults, fields
|
36
|
-
delegate :defaults, :fields, :to => "self.class"
|
34
|
+
delegate :defaults, :fields, :to => "self.class"
|
37
35
|
|
36
|
+
included do
|
38
37
|
field(:_type, :type => String)
|
39
38
|
field(:_id, :type => BSON::ObjectId)
|
40
39
|
|
@@ -88,13 +87,19 @@ module Mongoid #:nodoc
|
|
88
87
|
#
|
89
88
|
# @return [ Hash ] The field defaults.
|
90
89
|
def defaults
|
91
|
-
@defaults ||=
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
90
|
+
@defaults ||= []
|
91
|
+
end
|
92
|
+
|
93
|
+
# Set the defaults for the class.
|
94
|
+
#
|
95
|
+
# @example Set the defaults.
|
96
|
+
# Person.defaults = defaults
|
97
|
+
#
|
98
|
+
# @param [ Array ] defaults The array of defaults to set.
|
99
|
+
#
|
100
|
+
# @since 2.0.0.rc.6
|
101
|
+
def defaults=(defaults)
|
102
|
+
@defaults = defaults
|
98
103
|
end
|
99
104
|
|
100
105
|
# Defines all the fields that are accessible on the Document
|
@@ -113,6 +118,7 @@ module Mongoid #:nodoc
|
|
113
118
|
#
|
114
119
|
# @return [ Field ] The generated field
|
115
120
|
def field(name, options = {})
|
121
|
+
check_field_name!(name)
|
116
122
|
add_field(name.to_s, options)
|
117
123
|
end
|
118
124
|
|
@@ -152,7 +158,7 @@ module Mongoid #:nodoc
|
|
152
158
|
# @since 2.0.0.rc.6
|
153
159
|
def inherited(subclass)
|
154
160
|
super
|
155
|
-
subclass.fields = fields.dup
|
161
|
+
subclass.defaults, subclass.fields = defaults.dup, fields.dup
|
156
162
|
end
|
157
163
|
|
158
164
|
# Replace a field with a new type.
|
@@ -167,6 +173,7 @@ module Mongoid #:nodoc
|
|
167
173
|
#
|
168
174
|
# @since 2.1.0
|
169
175
|
def replace_field(name, type)
|
176
|
+
defaults.delete_one(name)
|
170
177
|
add_field(name, fields[name].options.merge(:type => type))
|
171
178
|
end
|
172
179
|
|
@@ -180,13 +187,12 @@ module Mongoid #:nodoc
|
|
180
187
|
# @param [ Symbol ] name The name of the field.
|
181
188
|
# @param [ Hash ] options The hash of options.
|
182
189
|
def add_field(name, options = {})
|
183
|
-
@defaults = nil if @defaults
|
184
|
-
|
185
190
|
meth = options.delete(:as) || name
|
186
191
|
Mappings.for(
|
187
192
|
options[:type], options[:identity]
|
188
193
|
).new(name, options).tap do |field|
|
189
194
|
fields[name] = field
|
195
|
+
defaults << name unless field.default.nil?
|
190
196
|
create_accessors(name, meth, options)
|
191
197
|
process_options(field)
|
192
198
|
|
@@ -222,6 +228,22 @@ module Mongoid #:nodoc
|
|
222
228
|
end
|
223
229
|
end
|
224
230
|
|
231
|
+
# Determine if the field name is allowed, if not raise an error.
|
232
|
+
#
|
233
|
+
# @example Check the field name.
|
234
|
+
# Model.check_field_name!(:collection)
|
235
|
+
#
|
236
|
+
# @param [ Symbol ] name The field name.
|
237
|
+
#
|
238
|
+
# @raise [ Errors::InvalidField ] If the name is not allowed.
|
239
|
+
#
|
240
|
+
# @since 2.1.8
|
241
|
+
def check_field_name!(name)
|
242
|
+
if Mongoid.destructive_fields.include?(name)
|
243
|
+
raise Errors::InvalidField.new(name)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
225
247
|
# Create the field accessors.
|
226
248
|
#
|
227
249
|
# @example Generate the accessors.
|
@@ -25,7 +25,7 @@ module Mongoid #:nodoc:
|
|
25
25
|
module Serializable
|
26
26
|
|
27
27
|
# Set readers for the instance variables.
|
28
|
-
attr_reader :
|
28
|
+
attr_reader :default, :label, :name, :options
|
29
29
|
|
30
30
|
# When reading the field do we need to cast the value? This holds true when
|
31
31
|
# times are stored or for big decimals which are stored as strings.
|
@@ -44,22 +44,6 @@ module Mongoid #:nodoc:
|
|
44
44
|
end.include?(:deserialize)
|
45
45
|
end
|
46
46
|
|
47
|
-
# Get the default value for the field.
|
48
|
-
#
|
49
|
-
# @example Get the default.
|
50
|
-
# field.default
|
51
|
-
#
|
52
|
-
# @return [ Object ] The default value.
|
53
|
-
#
|
54
|
-
# @since 2.1.0
|
55
|
-
def default
|
56
|
-
if default_value.respond_to?(:call)
|
57
|
-
serialize(default_value.call)
|
58
|
-
else
|
59
|
-
serialize(default_value)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
47
|
# Deserialize this field from the type stored in MongoDB to the type
|
64
48
|
# defined on the model
|
65
49
|
#
|
@@ -73,6 +57,25 @@ module Mongoid #:nodoc:
|
|
73
57
|
# @since 2.1.0
|
74
58
|
def deserialize(object); object; end
|
75
59
|
|
60
|
+
# Evaluate the default value and return it. Will handle the
|
61
|
+
# serialization, proc calls, and duplication if necessary.
|
62
|
+
#
|
63
|
+
# @example Evaluate the default value.
|
64
|
+
# field.eval_default(document)
|
65
|
+
#
|
66
|
+
# @param [ Document ] doc The document the field belongs to.
|
67
|
+
#
|
68
|
+
# @return [ Object ] The serialized default value.
|
69
|
+
#
|
70
|
+
# @since 2.1.8
|
71
|
+
def eval_default(doc)
|
72
|
+
if default.respond_to?(:call)
|
73
|
+
serialize(doc.instance_exec(&default))
|
74
|
+
else
|
75
|
+
serialize(default.duplicable? ? default.dup : default)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
76
79
|
# Create the new field with a name and optional additional options.
|
77
80
|
#
|
78
81
|
# @example Create the new field.
|
@@ -87,7 +90,7 @@ module Mongoid #:nodoc:
|
|
87
90
|
# @since 2.1.0
|
88
91
|
def initialize(name, options = {})
|
89
92
|
@name, @options = name, options
|
90
|
-
@
|
93
|
+
@default, @label = options[:default], options[:label]
|
91
94
|
end
|
92
95
|
|
93
96
|
# Serialize the object from the type defined in the model to a MongoDB
|
@@ -7,20 +7,6 @@ module Mongoid #:nodoc:
|
|
7
7
|
class Array
|
8
8
|
include Serializable
|
9
9
|
|
10
|
-
# Get the default value for the field. If the default is a proc call
|
11
|
-
# it, otherwise clone the array.
|
12
|
-
#
|
13
|
-
# @example Get the default.
|
14
|
-
# field.default
|
15
|
-
#
|
16
|
-
# @return [ Object ] The default value.
|
17
|
-
#
|
18
|
-
# @since 2.1.0
|
19
|
-
def default
|
20
|
-
return nil unless default_value
|
21
|
-
default_value.respond_to?(:call) ? default_value.call : default_value.dup
|
22
|
-
end
|
23
|
-
|
24
10
|
# Serialize the object from the type defined in the model to a MongoDB
|
25
11
|
# compatible object to store.
|
26
12
|
#
|
@@ -8,19 +8,6 @@ module Mongoid #:nodoc:
|
|
8
8
|
class Array
|
9
9
|
include Serializable
|
10
10
|
|
11
|
-
# Get the default value for the field. If the default is a proc call
|
12
|
-
# it, otherwise clone the array.
|
13
|
-
#
|
14
|
-
# @example Get the default.
|
15
|
-
# field.default
|
16
|
-
#
|
17
|
-
# @return [ Object ] The default value cloned.
|
18
|
-
#
|
19
|
-
# @since 2.1.0
|
20
|
-
def default
|
21
|
-
default_value.dup
|
22
|
-
end
|
23
|
-
|
24
11
|
# Serialize the object from the type defined in the model to a MongoDB
|
25
12
|
# compatible object to store.
|
26
13
|
#
|
@@ -5,20 +5,6 @@ module Mongoid #:nodoc:
|
|
5
5
|
# Defines the behaviour for hash fields.
|
6
6
|
class Hash
|
7
7
|
include Serializable
|
8
|
-
|
9
|
-
# Get the default value for the field. If the default is a proc call
|
10
|
-
# it, otherwise clone the array.
|
11
|
-
#
|
12
|
-
# @example Get the default.
|
13
|
-
# field.default
|
14
|
-
#
|
15
|
-
# @return [ Object ] The default value.
|
16
|
-
#
|
17
|
-
# @since 2.1.0
|
18
|
-
def default
|
19
|
-
return nil unless default_value
|
20
|
-
default_value.respond_to?(:call) ? default_value.call : default_value.dup
|
21
|
-
end
|
22
8
|
end
|
23
9
|
end
|
24
10
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mongoid #:nodoc:
|
3
|
+
module Fields #:nodoc:
|
4
|
+
module Serializable #:nodoc:
|
5
|
+
|
6
|
+
# Defines the behaviour for nil fields.
|
7
|
+
class NilClass
|
8
|
+
include Serializable
|
9
|
+
|
10
|
+
# Deserialize this field from the type stored in MongoDB to the type
|
11
|
+
# defined on the model
|
12
|
+
#
|
13
|
+
# @example Deserialize the field.
|
14
|
+
# field.deserialize(object)
|
15
|
+
#
|
16
|
+
# @param [ Object ] object The object to cast.
|
17
|
+
#
|
18
|
+
# @return [ nil ] Always nil.
|
19
|
+
#
|
20
|
+
# @since 2.1.0
|
21
|
+
def deserialize(object); nil; end
|
22
|
+
|
23
|
+
# Serialize the object from the type defined in the model to a MongoDB
|
24
|
+
# compatible object to store.
|
25
|
+
#
|
26
|
+
# @example Serialize the field.
|
27
|
+
# field.serialize(object)
|
28
|
+
#
|
29
|
+
# @param [ Object ] object The object to cast.
|
30
|
+
#
|
31
|
+
# @return [ nil ] always nil.
|
32
|
+
#
|
33
|
+
# @since 2.1.0
|
34
|
+
def serialize(object); nil; end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/mongoid/identity.rb
CHANGED
@@ -48,10 +48,8 @@ module Mongoid #:nodoc:
|
|
48
48
|
# @example Set the id.
|
49
49
|
# identity.identify
|
50
50
|
def identify
|
51
|
-
|
52
|
-
|
53
|
-
document.id = generate_id if document.id.blank?
|
54
|
-
end
|
51
|
+
document.id = compose.join(" ").identify if document.primary_key
|
52
|
+
document.id = generate_id if document.id.blank?
|
55
53
|
document.id
|
56
54
|
end
|
57
55
|
|
data/lib/mongoid/keys.rb
CHANGED
@@ -6,12 +6,12 @@ module Mongoid #:nodoc:
|
|
6
6
|
module Keys
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
|
+
attr_reader :identifier
|
10
|
+
delegate :primary_key, :using_object_ids?, :to => "self.class"
|
11
|
+
|
9
12
|
included do
|
10
13
|
cattr_accessor :primary_key, :using_object_ids
|
11
14
|
self.using_object_ids = true
|
12
|
-
delegate :primary_key, :using_object_ids?, :to => "self.class"
|
13
|
-
|
14
|
-
attr_reader :identifier
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
@@ -5,11 +5,11 @@ module Mongoid #:nodoc:
|
|
5
5
|
module NestedAttributes
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
+
delegate :nested_attributes, :to => "self.class"
|
9
|
+
|
8
10
|
included do
|
9
11
|
class_attribute :nested_attributes
|
10
12
|
self.nested_attributes = []
|
11
|
-
|
12
|
-
delegate :nested_attributes, :to => "self.class"
|
13
13
|
end
|
14
14
|
|
15
15
|
module ClassMethods #:nodoc:
|
data/lib/mongoid/railtie.rb
CHANGED
@@ -97,20 +97,6 @@ module Rails #:nodoc:
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
# This initializer warns the user that preloading models is set to false,
|
101
|
-
# and queries will be inconsistent in dev mode if models are using
|
102
|
-
# inheritance.
|
103
|
-
initializer "warn of preload models configuration" do |app|
|
104
|
-
config.after_initialize do
|
105
|
-
if !::Mongoid.preload_models && !Rails.configuration.cache_classes
|
106
|
-
puts "\nMongoid preload_models is set to false. If you are using"
|
107
|
-
puts "inheritance in your application model please set this to true or "
|
108
|
-
puts "you will experience querying inconsistencies in dev mode. Note that"
|
109
|
-
puts "this will severely decrease performance in dev mode only.\n\n"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
100
|
# Need to include the Mongoid identity map middleware.
|
115
101
|
initializer "include the identity map" do |app|
|
116
102
|
app.config.middleware.use "Rack::Mongoid::Middleware::IdentityMap"
|
@@ -53,12 +53,13 @@ module Mongoid #:nodoc:
|
|
53
53
|
#
|
54
54
|
# @since 2.0.0
|
55
55
|
def atomically(modifier, &block)
|
56
|
-
updater = Threaded.
|
56
|
+
updater = Threaded.update_consumer(root_class) ||
|
57
|
+
Threaded.set_update_consumer(root_class, MODIFIERS[modifier].new)
|
57
58
|
count_executions do
|
58
59
|
block.call if block
|
59
60
|
end.tap do
|
60
61
|
if @executions.zero?
|
61
|
-
Threaded.
|
62
|
+
Threaded.set_update_consumer(root_class, nil)
|
62
63
|
updater.execute(collection)
|
63
64
|
end
|
64
65
|
end
|
@@ -7,6 +7,10 @@ module Mongoid # :nodoc:
|
|
7
7
|
module Macros
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
|
+
# Convenience methods for the instance to know about attributes that
|
11
|
+
# are located at the class level.
|
12
|
+
delegate :associations, :relations, :to => "self.class"
|
13
|
+
|
10
14
|
included do
|
11
15
|
cattr_accessor :embedded
|
12
16
|
class_attribute :relations
|
@@ -21,10 +25,6 @@ module Mongoid # :nodoc:
|
|
21
25
|
alias :associations :relations
|
22
26
|
alias :embedded? :embedded
|
23
27
|
end
|
24
|
-
|
25
|
-
# Convenience methods for the instance to know about attributes that
|
26
|
-
# are located at the class level.
|
27
|
-
delegate :associations, :relations, :to => "self.class"
|
28
28
|
end
|
29
29
|
|
30
30
|
module ClassMethods #:nodoc:
|
@@ -17,6 +17,20 @@ module Mongoid # :nodoc:
|
|
17
17
|
def in_memory
|
18
18
|
[ target ]
|
19
19
|
end
|
20
|
+
|
21
|
+
# Since method_missing is overridden we should override this as well.
|
22
|
+
#
|
23
|
+
# @example Does the proxy respond to the method?
|
24
|
+
# relation.respond_to?(:name)
|
25
|
+
#
|
26
|
+
# @param [ Symbol ] name The method name.
|
27
|
+
#
|
28
|
+
# @return [ true, false ] If the proxy responds to the method.
|
29
|
+
#
|
30
|
+
# @since 2.1.8
|
31
|
+
def respond_to?(name, include_private = false)
|
32
|
+
target.respond_to?(name, include_private) || super
|
33
|
+
end
|
20
34
|
end
|
21
35
|
end
|
22
36
|
end
|
@@ -151,6 +151,18 @@ module Mongoid # :nodoc:
|
|
151
151
|
def raise_unsaved(doc)
|
152
152
|
raise Errors::UnsavedDocument.new(base, doc)
|
153
153
|
end
|
154
|
+
|
155
|
+
# Get the class of the root document in the hierarchy.
|
156
|
+
#
|
157
|
+
# @example Get the root's class.
|
158
|
+
# proxy.root_class
|
159
|
+
#
|
160
|
+
# @return [ Class ] The root class.
|
161
|
+
#
|
162
|
+
# @since 2.1.8
|
163
|
+
def root_class
|
164
|
+
@root_class ||= base._root.class
|
165
|
+
end
|
154
166
|
end
|
155
167
|
end
|
156
168
|
end
|
@@ -40,8 +40,8 @@ module Mongoid # :nodoc:
|
|
40
40
|
def substitute(replacement)
|
41
41
|
tap do |proxy|
|
42
42
|
proxy.unbind_one
|
43
|
-
proxy.target.delete if persistable?
|
44
43
|
return nil unless replacement
|
44
|
+
proxy.target.delete if persistable?
|
45
45
|
proxy.target = replacement
|
46
46
|
proxy.bind_one
|
47
47
|
end
|
@@ -7,12 +7,9 @@ module Mongoid # :nodoc:
|
|
7
7
|
module Reflections
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
:reflect_on_association,
|
14
|
-
:reflect_on_all_associations, :to => "self.class"
|
15
|
-
end
|
10
|
+
delegate \
|
11
|
+
:reflect_on_association,
|
12
|
+
:reflect_on_all_associations, :to => "self.class"
|
16
13
|
|
17
14
|
module ClassMethods #:nodoc
|
18
15
|
|
data/lib/mongoid/sharding.rb
CHANGED
@@ -5,11 +5,11 @@ module Mongoid #:nodoc
|
|
5
5
|
module Sharding
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
+
delegate :shard_key_fields, :to => "self.class"
|
9
|
+
|
8
10
|
included do
|
9
11
|
cattr_accessor :shard_key_fields
|
10
12
|
self.shard_key_fields = []
|
11
|
-
|
12
|
-
delegate :shard_key_fields, :to => "self.class"
|
13
13
|
end
|
14
14
|
|
15
15
|
# Get the document selector with the defined shard keys.
|
data/lib/mongoid/threaded.rb
CHANGED
@@ -154,8 +154,8 @@ module Mongoid #:nodoc:
|
|
154
154
|
# @return [ Object ] The atomic update consumer.
|
155
155
|
#
|
156
156
|
# @since 2.1.0
|
157
|
-
def
|
158
|
-
Thread.current[:"[mongoid]:update-consumer"]
|
157
|
+
def update_consumer(klass)
|
158
|
+
Thread.current[:"[mongoid][#{klass}]:update-consumer"]
|
159
159
|
end
|
160
160
|
|
161
161
|
# Set the update consumer on the current thread.
|
@@ -168,8 +168,8 @@ module Mongoid #:nodoc:
|
|
168
168
|
# @return [ Object ] The update consumer.
|
169
169
|
#
|
170
170
|
# @since 2.1.0
|
171
|
-
def
|
172
|
-
Thread.current[:"[mongoid]:update-consumer"] = consumer
|
171
|
+
def set_update_consumer(klass, consumer)
|
172
|
+
Thread.current[:"[mongoid][#{klass}]:update-consumer"] = consumer
|
173
173
|
end
|
174
174
|
end
|
175
175
|
end
|
data/lib/mongoid/version.rb
CHANGED
data/lib/mongoid/versioning.rb
CHANGED
@@ -7,6 +7,8 @@ module Mongoid #:nodoc:
|
|
7
7
|
module Versioning
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
|
+
delegate :version_max, :to => "self.class"
|
11
|
+
|
10
12
|
included do
|
11
13
|
field :version, :type => Integer, :default => 1
|
12
14
|
|
@@ -20,7 +22,6 @@ module Mongoid #:nodoc:
|
|
20
22
|
set_callback :save, :before, :revise, :if => :revisable?
|
21
23
|
|
22
24
|
class_attribute :version_max
|
23
|
-
delegate :version_max, :to => "self.class"
|
24
25
|
self.cyclic = true
|
25
26
|
end
|
26
27
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-16 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
16
|
-
requirement: &
|
16
|
+
requirement: &70188037296020 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70188037296020
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: tzinfo
|
27
|
-
requirement: &
|
27
|
+
requirement: &70188037295340 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.3.22
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70188037295340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: mongo
|
38
|
-
requirement: &
|
38
|
+
requirement: &70188037294640 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '1.3'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70188037294640
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &70188037293900 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 3.5.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70188037293900
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bson_ext
|
60
|
-
requirement: &
|
60
|
+
requirement: &70188037293360 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '1.3'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70188037293360
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mocha
|
71
|
-
requirement: &
|
71
|
+
requirement: &70188037292580 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 0.9.8
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70188037292580
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rspec
|
82
|
-
requirement: &
|
82
|
+
requirement: &70188037291660 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '2.6'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70188037291660
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: watchr
|
93
|
-
requirement: &
|
93
|
+
requirement: &70188037290960 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0.6'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70188037290960
|
102
102
|
description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
|
103
103
|
in Ruby.
|
104
104
|
email:
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- lib/mongoid/fields/serializable/foreign_keys/object.rb
|
212
212
|
- lib/mongoid/fields/serializable/hash.rb
|
213
213
|
- lib/mongoid/fields/serializable/integer.rb
|
214
|
+
- lib/mongoid/fields/serializable/nil_class.rb
|
214
215
|
- lib/mongoid/fields/serializable/object.rb
|
215
216
|
- lib/mongoid/fields/serializable/object_id.rb
|
216
217
|
- lib/mongoid/fields/serializable/range.rb
|
@@ -379,7 +380,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
379
380
|
version: '0'
|
380
381
|
segments:
|
381
382
|
- 0
|
382
|
-
hash:
|
383
|
+
hash: -2233289623287425963
|
383
384
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
384
385
|
none: false
|
385
386
|
requirements:
|