options_model 0.0.4 → 0.0.5
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
- data/lib/options_model/concerns/attributes.rb +11 -2
- data/lib/options_model/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49f062b3a41f61cb5c5247eed2551c52785c0987
|
4
|
+
data.tar.gz: 18b414a537123b4e90f80125d216a882d0208cf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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}]
|
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}]
|
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}"
|
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
|
+
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-
|
11
|
+
date: 2017-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|