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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 928b2c13156001ffe932ffa4201615a28104110b
4
- data.tar.gz: e6600e3388d6de69f86435e48b4cdc4c9574da34
3
+ metadata.gz: fd257f582c3267f141ccd5672f2de45977cc642b
4
+ data.tar.gz: 47ba60150ca1fe1661f19c1ad9f9e7fcd2df6ae3
5
5
  SHA512:
6
- metadata.gz: 19438b72f6df2eb261fc584c57f73bb0e1fa7b259d14335f124a0e7882aa5028fbc9f528e921c84c9a081499ac403fa91b1abf18d27db7eefaead3946fefa293
7
- data.tar.gz: 94b87661afaefde981345e4c43ae887c5308736b39d80649f33e17df56772dfa54677e6ec6ea692e8d748551d165fae80fbb2f587617cdc3d482d00ef8989dba
6
+ metadata.gz: df21aa404447a4acf7a13cb3390692d35ab53e91ca257c908cd5be197e8ea05a7fbdb6619b26d91fed1f173b02844b44d92816b7e7dd88e76c7b1d4c76b2818e
7
+ data.tar.gz: aaefea258bc8d5edf32322d7d9784d405207eec162a2b1f9a10594326107064f6bd718ede54fc6f911f9f172176b1cf7dc64f0dac50cc5c07e34fd7bb7c9f86d
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
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.2.0
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-08-07 00:00:00.000000000 Z
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: