mongoid 6.1.0.rc0 → 6.1.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -3
- data/README.md +2 -2
- data/lib/mongoid/attributes.rb +12 -0
- data/lib/mongoid/attributes/dynamic.rb +3 -3
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/criteria.rb +2 -0
- data/lib/mongoid/criteria/queryable.rb +1 -0
- data/lib/mongoid/criteria/queryable/forwardable.rb +2 -2
- data/lib/mongoid/document.rb +1 -0
- data/lib/mongoid/persistable/settable.rb +3 -1
- data/lib/mongoid/persistable/updatable.rb +1 -6
- data/lib/mongoid/relations/accessors.rb +1 -1
- data/lib/mongoid/relations/builders.rb +2 -2
- data/lib/mongoid/relations/eager.rb +2 -2
- data/lib/mongoid/relations/reflections.rb +5 -3
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/scopable.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +2 -2
- data/spec/app/models/dokument.rb +1 -0
- data/spec/app/models/subscription.rb +1 -0
- data/spec/mongoid/attributes_spec.rb +15 -0
- data/spec/mongoid/persistable/settable_spec.rb +44 -0
- data/spec/mongoid/persistable/updatable_spec.rb +18 -0
- data/spec/mongoid/relations/cyclic_spec.rb +22 -0
- data/spec/mongoid/relations/reflections_spec.rb +9 -9
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c57e0133222699f9072fe67b609e7212327028ff
|
4
|
+
data.tar.gz: f2f799925ab8ca3b9126b16fe5a8d52c03fb1146
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8139bde85b47d8920a022f4f1a3c68796c446192128be7a7ceb59607c82be58404a956e89676e61ce61a6f39fd691b4b8f39bf2a31663ef64f482a5271986484
|
7
|
+
data.tar.gz: d500146fa38cbdf1e5d915fa164ef465f4b0ba3ffc7568d77fc85bc9576b61dab8efdbffa42ff8fb2b72063997b8207c264ec52a2f11c04140f09c2a5532b778
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1 @@
|
|
1
|
-
|
2
|
-
�����8XOGi�7w���_[��݁�Ҟ��H��pļ\ D�0��@�WU=������j.���
|
3
|
-
�3�������U%��h�:w2A���R����(٘0�PbK����:Q4( ���)Q����T�ݧ~�F��:�[�U��=@:�<̯�1�.�
|
1
|
+
xp���ewE���lSeCQݔ�oNѨ+jSF7���0p�*=-2U����?ЌG�E��`a#K�|#�i�e��Z���cB�?��l=�LL�Q��K�>�bB#w�{B �q�b>$2��(ٛL� k��G���_ ˸,,��%Z�}n��k�2빎$Ґ��&I���"�$oͮ,cIt&b2 :�ܭ���y����vz؟��k�;����l�w>��\�=E��<�ˬ����o��a��
|
data/README.md
CHANGED
@@ -26,12 +26,12 @@ Mongoid is tested against MRI 2.2, 2.3 and JRuby (9.1).
|
|
26
26
|
Documentation
|
27
27
|
-------------
|
28
28
|
|
29
|
-
Please see the [MongoDB website](http://docs.mongodb.org/ecosystem/tutorial/ruby-mongoid-tutorial/#ruby-mongoid-tutorial) for up-to-date documentation
|
29
|
+
Please see the [MongoDB website](http://docs.mongodb.org/ecosystem/tutorial/ruby-mongoid-tutorial/#ruby-mongoid-tutorial) for up-to-date documentation.
|
30
30
|
|
31
31
|
License
|
32
32
|
-------
|
33
33
|
|
34
|
-
Copyright (c) 2009-
|
34
|
+
Copyright (c) 2009-2017 Durran Jordan
|
35
35
|
|
36
36
|
Permission is hereby granted, free of charge, to any person obtaining
|
37
37
|
a copy of this software and associated documentation files (the
|
data/lib/mongoid/attributes.rb
CHANGED
@@ -242,6 +242,18 @@ module Mongoid
|
|
242
242
|
(selection.values.first == 1 && !selection_included?(name, selection, field))
|
243
243
|
end
|
244
244
|
|
245
|
+
# Return type-casted attributes.
|
246
|
+
#
|
247
|
+
# @example Type-casted attributes.
|
248
|
+
# document.typed_attributes
|
249
|
+
#
|
250
|
+
# @return [ Object ] The hash with keys and values of the type-casted attributes.
|
251
|
+
#
|
252
|
+
# @since 6.1.0
|
253
|
+
def typed_attributes
|
254
|
+
attribute_names.map { |name| [name, send(name)] }.to_h
|
255
|
+
end
|
256
|
+
|
245
257
|
private
|
246
258
|
|
247
259
|
def selection_excluded?(name, selection, field)
|
@@ -37,7 +37,7 @@ module Mongoid
|
|
37
37
|
# @since 4.0.0
|
38
38
|
def define_dynamic_reader(name)
|
39
39
|
return unless name.valid_method_name?
|
40
|
-
class_eval <<-READER
|
40
|
+
class_eval <<-READER, __FILE__, __LINE__ + 1
|
41
41
|
def #{name}
|
42
42
|
attribute_will_change!(#{name.inspect})
|
43
43
|
read_attribute(#{name.inspect})
|
@@ -56,7 +56,7 @@ module Mongoid
|
|
56
56
|
#
|
57
57
|
# @since 4.0.0
|
58
58
|
def define_dynamic_before_type_cast_reader(name)
|
59
|
-
class_eval <<-READER
|
59
|
+
class_eval <<-READER, __FILE__, __LINE__ + 1
|
60
60
|
def #{name}_before_type_cast
|
61
61
|
attribute_will_change!(#{name.inspect})
|
62
62
|
read_attribute_before_type_cast(#{name.inspect})
|
@@ -77,7 +77,7 @@ module Mongoid
|
|
77
77
|
def define_dynamic_writer(name)
|
78
78
|
return unless name.valid_method_name?
|
79
79
|
|
80
|
-
class_eval <<-WRITER
|
80
|
+
class_eval <<-WRITER, __FILE__, __LINE__ + 1
|
81
81
|
def #{name}=(value)
|
82
82
|
write_attribute(#{name.inspect}, value)
|
83
83
|
end
|
data/lib/mongoid/criteria.rb
CHANGED
@@ -46,13 +46,13 @@ module Mongoid
|
|
46
46
|
# @since 1.0.0
|
47
47
|
def __forward__(name, receiver)
|
48
48
|
if self.class == Module
|
49
|
-
module_eval <<-SEL
|
49
|
+
module_eval <<-SEL, __FILE__, __LINE__ + 1
|
50
50
|
def #{name}(*args, &block)
|
51
51
|
#{receiver}.__send__(:#{name}, *args, &block)
|
52
52
|
end
|
53
53
|
SEL
|
54
54
|
else
|
55
|
-
|
55
|
+
singleton_class.class_eval <<-SEL, __FILE__, __LINE__ + 1
|
56
56
|
def #{name}(*args, &block)
|
57
57
|
#{receiver}.__send__(:#{name}, *args, &block)
|
58
58
|
end
|
data/lib/mongoid/document.rb
CHANGED
@@ -27,7 +27,9 @@ module Mongoid
|
|
27
27
|
field = field_and_value_hash.keys.first.to_s
|
28
28
|
|
29
29
|
if fields[field] && fields[field].type == Hash && attributes.key?(field)
|
30
|
-
|
30
|
+
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
|
31
|
+
value = attributes[field].merge(field_and_value_hash[field], &merger)
|
32
|
+
process_attribute(field.to_s, value)
|
31
33
|
else
|
32
34
|
process_attribute(field.to_s, field_and_value_hash[field])
|
33
35
|
end
|
@@ -26,12 +26,7 @@ module Mongoid
|
|
26
26
|
def update_attribute(name, value)
|
27
27
|
as_writable_attribute!(name, value) do |access|
|
28
28
|
normalized = name.to_s
|
29
|
-
|
30
|
-
if respond_to?(setter)
|
31
|
-
send(setter, value)
|
32
|
-
else
|
33
|
-
write_attribute(access, value)
|
34
|
-
end
|
29
|
+
process_attribute(normalized, value)
|
35
30
|
save(validate: false)
|
36
31
|
end
|
37
32
|
end
|
@@ -64,7 +64,7 @@ module Mongoid
|
|
64
64
|
# @since 2.0.0.rc.1
|
65
65
|
def builder(name, metadata)
|
66
66
|
re_define_method("build_#{name}") do |*args|
|
67
|
-
attributes,
|
67
|
+
attributes, _options = parse_args(*args)
|
68
68
|
document = Factory.build(metadata.klass, attributes)
|
69
69
|
_building do
|
70
70
|
child = send("#{name}=", document)
|
@@ -89,7 +89,7 @@ module Mongoid
|
|
89
89
|
# @since 2.0.0.rc.1
|
90
90
|
def creator(name, metadata)
|
91
91
|
re_define_method("create_#{name}") do |*args|
|
92
|
-
attributes,
|
92
|
+
attributes, _options = parse_args(*args)
|
93
93
|
document = Factory.build(metadata.klass, attributes)
|
94
94
|
doc = _assigning do
|
95
95
|
send("#{name}=", document)
|
@@ -24,7 +24,7 @@ module Mongoid
|
|
24
24
|
# @example Find multiple relation metadata by macro.
|
25
25
|
# person.reflect_on_all_associations(:embeds_many)
|
26
26
|
#
|
27
|
-
# @param [ Array<
|
27
|
+
# @param [ Array<Symbol> ] *macros The relation macros.
|
28
28
|
#
|
29
29
|
# @return [ Array<Metadata> ] The matching relation metadata.
|
30
30
|
def reflect_on_all_associations(*macros)
|
@@ -50,11 +50,13 @@ module Mongoid
|
|
50
50
|
# @example Find multiple relation metadata by macro.
|
51
51
|
# Person.reflect_on_all_associations(:embeds_many)
|
52
52
|
#
|
53
|
-
# @param [ Array<
|
53
|
+
# @param [ Array<Symbol> ] *macros The relation macros.
|
54
54
|
#
|
55
55
|
# @return [ Array<Metadata> ] The matching relation metadata.
|
56
56
|
def reflect_on_all_associations(*macros)
|
57
|
-
relations.values
|
57
|
+
association_reflections = relations.values
|
58
|
+
association_reflections.select! { |reflection| macros.include?(reflection.macro) } unless macros.empty?
|
59
|
+
association_reflections
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
@@ -81,7 +81,7 @@ module Mongoid
|
|
81
81
|
# @return [ Symbol ] The method name.
|
82
82
|
def define_relation_touch_method(name, extra_field = nil)
|
83
83
|
method_name = "touch_#{name}_after_create_or_destroy"
|
84
|
-
class_eval <<-TOUCH
|
84
|
+
class_eval <<-TOUCH, __FILE__, __LINE__ + 1
|
85
85
|
def #{method_name}
|
86
86
|
without_autobuild do
|
87
87
|
relation = __send__(:#{name})
|
data/lib/mongoid/scopable.rb
CHANGED
@@ -117,7 +117,7 @@ module Mongoid
|
|
117
117
|
# @since 3.0.0
|
118
118
|
def queryable
|
119
119
|
crit = Threaded.current_scope(self) || Criteria.new(self)
|
120
|
-
crit.embedded = true if crit.klass.embedded?
|
120
|
+
crit.embedded = true if (crit.klass.embedded? && !crit.klass.cyclic?)
|
121
121
|
crit
|
122
122
|
end
|
123
123
|
|
data/lib/mongoid/version.rb
CHANGED
@@ -51,8 +51,8 @@ development:
|
|
51
51
|
# via ismaster commands. (default: 10)
|
52
52
|
# heartbeat_frequency: 10
|
53
53
|
|
54
|
-
# The time in seconds for selecting servers for a near read preference. (default:
|
55
|
-
# local_threshold:
|
54
|
+
# The time in seconds for selecting servers for a near read preference. (default: 0.015)
|
55
|
+
# local_threshold: 0.015
|
56
56
|
|
57
57
|
# The timeout in seconds for selecting a server for an operation. (default: 30)
|
58
58
|
# server_selection_timeout: 30
|
data/spec/app/models/dokument.rb
CHANGED
@@ -1385,6 +1385,21 @@ describe Mongoid::Attributes do
|
|
1385
1385
|
end
|
1386
1386
|
end
|
1387
1387
|
|
1388
|
+
describe "#typed_attributes" do
|
1389
|
+
|
1390
|
+
let(:date_time) do
|
1391
|
+
DateTime.current
|
1392
|
+
end
|
1393
|
+
|
1394
|
+
let(:user) do
|
1395
|
+
User.new(last_login: date_time)
|
1396
|
+
end
|
1397
|
+
|
1398
|
+
it 'returns typecasted attributes' do
|
1399
|
+
expect(user.typed_attributes).to include("last_login" => date_time)
|
1400
|
+
end
|
1401
|
+
end
|
1402
|
+
|
1388
1403
|
[:attributes=, :write_attributes].each do |method|
|
1389
1404
|
|
1390
1405
|
describe "##{method}" do
|
@@ -261,6 +261,50 @@ describe Mongoid::Persistable::Settable do
|
|
261
261
|
expect(church.reload.location).to eq({ 'city' => 'Berlin', 'street' => 'Yorckstr.'})
|
262
262
|
end
|
263
263
|
end
|
264
|
+
|
265
|
+
context 'when the field is a bested hash' do
|
266
|
+
|
267
|
+
context 'when a leaf value in the nested hash is updated' do
|
268
|
+
|
269
|
+
let(:church) do
|
270
|
+
Church.new.tap do |a|
|
271
|
+
a.location = {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}}
|
272
|
+
a.name = 'Church1'
|
273
|
+
a.save
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
before do
|
278
|
+
church.set('location.address.city' => 'Munich')
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'does not reset the nested hash' do
|
282
|
+
expect(church.name).to eq('Church1')
|
283
|
+
expect(church.location).to eql({'address' => {'city' => 'Munich', 'street' => 'Yorckstr'}})
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
context 'when the nested hash is many levels deep' do
|
289
|
+
|
290
|
+
let(:church) do
|
291
|
+
Church.new.tap do |a|
|
292
|
+
a.location = {'address' => {'state' => {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}}}}
|
293
|
+
a.name = 'Church1'
|
294
|
+
a.save
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
before do
|
299
|
+
church.set('location.address.state.address.city' => 'Munich')
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'does not reset the nested hash' do
|
303
|
+
expect(church.name).to eq('Church1')
|
304
|
+
expect(church.location).to eql({'address' => {'state' => {'address' => {'city' => 'Munich', 'street' => 'Yorckstr'}}}})
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
264
308
|
end
|
265
309
|
|
266
310
|
context 'when the field is not already set locally' do
|
@@ -112,6 +112,24 @@ describe Mongoid::Persistable::Updatable do
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
context "when dynamic attributes are not enabled" do
|
116
|
+
|
117
|
+
it "raises exception for an unknown attribute " do
|
118
|
+
account = Account.create
|
119
|
+
|
120
|
+
expect {
|
121
|
+
account.update_attribute(:somethingnew, "somethingnew")
|
122
|
+
}.to raise_error(Mongoid::Errors::UnknownAttribute)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "will update value of aliased field" do
|
126
|
+
person = Person.create
|
127
|
+
person.update_attribute(:t, "test_value")
|
128
|
+
expect(person.reload.t).to eq "test_value"
|
129
|
+
expect(person.test).to eq "test_value"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
115
133
|
context "when provided a symbol attribute name" do
|
116
134
|
|
117
135
|
let(:post) do
|
@@ -21,6 +21,17 @@ describe Mongoid::Relations::Cyclic do
|
|
21
21
|
it "sets cyclic to true" do
|
22
22
|
expect(document.cyclic).to be true
|
23
23
|
end
|
24
|
+
|
25
|
+
context "when a query is executed" do
|
26
|
+
|
27
|
+
before do
|
28
|
+
document.save
|
29
|
+
end
|
30
|
+
|
31
|
+
it "queries the database, not memory" do
|
32
|
+
expect(Role.first).to be_a(Role)
|
33
|
+
end
|
34
|
+
end
|
24
35
|
end
|
25
36
|
|
26
37
|
context "when the name is not inflected easily" do
|
@@ -133,6 +144,17 @@ describe Mongoid::Relations::Cyclic do
|
|
133
144
|
expect(document.class.relations['child_mango']).to be_cascading_callbacks
|
134
145
|
end
|
135
146
|
end
|
147
|
+
|
148
|
+
context "when a query is executed" do
|
149
|
+
|
150
|
+
before do
|
151
|
+
document.save
|
152
|
+
end
|
153
|
+
|
154
|
+
it "queries the database, not memory" do
|
155
|
+
expect(Shelf.first).to be_a(Shelf)
|
156
|
+
end
|
157
|
+
end
|
136
158
|
end
|
137
159
|
|
138
160
|
context "when building a namespaced hierarchy" do
|
@@ -74,23 +74,23 @@ describe Mongoid::Relations::Reflections do
|
|
74
74
|
expect(relations.size).to eq(1)
|
75
75
|
end
|
76
76
|
end
|
77
|
-
end
|
78
77
|
|
79
|
-
|
78
|
+
context "when no argument supplied" do
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
let(:relations) do
|
81
|
+
klass.reflect_on_all_associations
|
82
|
+
end
|
84
83
|
|
85
|
-
|
86
|
-
|
84
|
+
it "returns an array of all relations" do
|
85
|
+
expect(relations.size).to eq(3)
|
86
|
+
end
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
context "when no
|
90
|
+
context "when no relations exist for the macros" do
|
91
91
|
|
92
92
|
let(:relations) do
|
93
|
-
klass.reflect_on_all_associations
|
93
|
+
klass.reflect_on_all_associations(:embeds_one)
|
94
94
|
end
|
95
95
|
|
96
96
|
it "returns an empty array" do
|
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: 6.1.0
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
cGiNQIiHBj/9/xHfOyOthBPUevTiVnuffarDr434z/LGLwYzgaG5EcJFvZqpvUpP
|
31
31
|
fGcAPtAZUMGLXwcOB1BJEFkDxUQIJiEpSmf4YzzZhEM=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
33
|
+
date: 2017-01-26 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activemodel
|
@@ -862,7 +862,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
862
862
|
version: 1.3.6
|
863
863
|
requirements: []
|
864
864
|
rubyforge_project: mongoid
|
865
|
-
rubygems_version: 2.
|
865
|
+
rubygems_version: 2.4.5.1
|
866
866
|
signing_key:
|
867
867
|
specification_version: 4
|
868
868
|
summary: Elegant Persistence in Ruby for MongoDB.
|
metadata.gz.sig
CHANGED
Binary file
|