mongoid-dsl 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/mongoid-dsl/fields-ext.rb +48 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd257f582c3267f141ccd5672f2de45977cc642b
|
4
|
+
data.tar.gz: 47ba60150ca1fe1661f19c1ad9f9e7fcd2df6ae3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df21aa404447a4acf7a13cb3390692d35ab53e91ca257c908cd5be197e8ea05a7fbdb6619b26d91fed1f173b02844b44d92816b7e7dd88e76c7b1d4c76b2818e
|
7
|
+
data.tar.gz: aaefea258bc8d5edf32322d7d9784d405207eec162a2b1f9a10594326107064f6bd718ede54fc6f911f9f172176b1cf7dc64f0dac50cc5c07e34fd7bb7c9f86d
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
@@ -256,5 +256,53 @@ end
|
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
#> cause the field become protected and only be changed throught helper methods
|
263
|
+
[ :protected, :defended ].each do |name_to_use|
|
264
|
+
Mongoid::Fields.option name_to_use do |model, field, value|
|
265
|
+
|
266
|
+
field.instance_variable_get('@options')[:protected]= !!field.instance_variable_get('@options').delete(name_to_use)
|
267
|
+
|
268
|
+
if value
|
269
|
+
|
270
|
+
model.class_eval do
|
271
|
+
|
272
|
+
define_method("protected_#{field.name}=") do |new_value|
|
273
|
+
self.instance_variable_get(:@protected_attributes)[field.name]=new_value
|
274
|
+
self[field.name]=new_value
|
275
|
+
end
|
276
|
+
|
277
|
+
alias_method "set_protected_#{field.name}","protected_#{field.name}="
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
model.instance_eval do
|
282
|
+
|
283
|
+
after_initialize do |doc|
|
284
|
+
|
285
|
+
unless doc.instance_variable_get(:@protected_attributes)
|
286
|
+
doc.instance_variable_set(:@protected_attributes,{})
|
287
|
+
end
|
288
|
+
|
289
|
+
doc.instance_variable_get(:@protected_attributes
|
290
|
+
)[field.name] = doc.instance_variable_get(:@attributes)[field.name]
|
291
|
+
|
292
|
+
end
|
293
|
+
|
294
|
+
before_save do |doc|
|
295
|
+
if doc.instance_variable_get(:@protected_attributes)
|
296
|
+
doc.instance_variable_get(:@protected_attributes).each_pair do |k,v|
|
297
|
+
doc.instance_variable_get(:@attributes)[k]=v
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|
259
307
|
end
|
260
308
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,3 +128,4 @@ signing_key:
|
|
128
128
|
specification_version: 4
|
129
129
|
summary: Ruby Module for ease of use mongoid models
|
130
130
|
test_files: []
|
131
|
+
has_rdoc:
|