options_model 0.0.4 → 0.0.5

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: c137c194481be3add8c0ffdaefe2ccfb35e697ce
4
- data.tar.gz: 3088d2da15e69fb0ab15c37a37669f1b93e59c38
3
+ metadata.gz: 49f062b3a41f61cb5c5247eed2551c52785c0987
4
+ data.tar.gz: 18b414a537123b4e90f80125d216a882d0208cf6
5
5
  SHA512:
6
- metadata.gz: 2c10190f8502e9b3f1ad1692d1ad510a5f7b952f25136df8658bf18b4ef907795465e2a114ea3df8feb13bee10731dc5354d5c77006957b9cf8d0208c0e3ba73
7
- data.tar.gz: ccd5d5ad6cad61e317851886cbbb12f6af3c8f1a3b30253b7c932682c93b80ceaaf954f3852aee2c62a097e4a36c4255ae623169d4e4120e31a75954be2a871e
6
+ metadata.gz: 84be83b6511d112cb405c861946257a14a71e46781d89ecf74c352fdd151982fe1aba16a1a1c1a6ead01a0cf838886b2eb87ecad144549af2ce75a06ed13ec00
7
+ data.tar.gz: 793a198caca6fd8d5621bd24d58eb17139f408bc420c67c050352adea167064dbcb7c2997c878331a1fff180b760e4257fc1b7cae2ab6b9fe3cc4074ea9443a6
@@ -13,13 +13,22 @@ module OptionsModel
13
13
  ActiveModel::Type.lookup(cast_type)
14
14
 
15
15
  attribute_defaults[name] = default
16
+ default_extractor =
17
+ case
18
+ when default.respond_to?(:call)
19
+ ".call"
20
+ when default.duplicable?
21
+ ".deep_dup"
22
+ else
23
+ ""
24
+ end
16
25
 
17
26
  generated_attribute_methods.synchronize do
18
27
  generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
19
28
  def #{name}
20
29
  value = attributes[:#{name}]
21
30
  return value unless value.nil?
22
- attributes[:#{name}] = self.class.attribute_defaults[:#{name}].#{default.respond_to?(:call) ? "call" : "dup"}
31
+ attributes[:#{name}] = self.class.attribute_defaults[:#{name}]#{default_extractor}
23
32
  attributes[:#{name}]
24
33
  end
25
34
  STR
@@ -30,7 +39,7 @@ module OptionsModel
30
39
  if value.respond_to?(:to_a)
31
40
  attributes[:#{name}] = value.to_a.map { |i| ActiveModel::Type.lookup(:#{cast_type}).cast(i) }
32
41
  elsif value.nil?
33
- attributes[:#{name}] = self.class.attribute_defaults[:#{name}].#{default.respond_to?(:call) ? "call" : "dup"}
42
+ attributes[:#{name}] = self.class.attribute_defaults[:#{name}]#{default_extractor}
34
43
  else
35
44
  raise ArgumentError,
36
45
  "`value` should respond to `to_a`, but got \#{value.class} -- \#{value.inspect}"
@@ -1,3 +1,3 @@
1
1
  module OptionsModel
2
- VERSION = "0.0.4".freeze
2
+ VERSION = "0.0.5".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: options_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-15 00:00:00.000000000 Z
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel