data_steroid 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/data_steroid/properties.rb +5 -5
- data/lib/data_steroid/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d21c1b531a84b0697685ee26a421b7a56be967ab
|
4
|
+
data.tar.gz: 2b5ff75e423fde47636072d39bee636c2ad05204
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b91bd9dadb3913ee1bb4986d8966446258c1df86970b55d3ae11e4f48eefbc5836a285acc22b65694769f97b14275e53ed359a36b1b4826bb565b0a87dc1fb4b
|
7
|
+
data.tar.gz: 1a8395bc413bbd51d3dff61e3b02fe55bd06cf6abc8f5776efffe544a7ffaed8d3e6d8eeab6b86d95587353f49141addcc3bf46ceb05541c5ce251a42eb35a47
|
@@ -62,7 +62,7 @@ module DataSteroid
|
|
62
62
|
def coerce_array(value, type)
|
63
63
|
# type: generic Array
|
64
64
|
if type == Array
|
65
|
-
|
65
|
+
coerce_other(value, type)
|
66
66
|
# type: Array[Something]
|
67
67
|
elsif value.respond_to?(:map)
|
68
68
|
value.map do |element|
|
@@ -76,11 +76,11 @@ module DataSteroid
|
|
76
76
|
def coerce_hash(value, type)
|
77
77
|
# type: generic Hash
|
78
78
|
if type == Hash
|
79
|
-
|
79
|
+
coerce_other(value, type)
|
80
80
|
# type: Hash[Something => Other thing]
|
81
|
-
elsif value.
|
81
|
+
elsif value.respond_to?(:to_h)
|
82
82
|
k_type, v_type = type.to_a[0]
|
83
|
-
value.map{ |k,
|
83
|
+
value.to_h.map{ |k,v| [ coerce(k, k_type), coerce(v, v_type) ] }.to_h
|
84
84
|
else
|
85
85
|
raise ArgumentError.new "Invalid coercion: #{value.class} => #{type}"
|
86
86
|
end
|
@@ -107,7 +107,7 @@ module DataSteroid
|
|
107
107
|
# or like this:
|
108
108
|
# property :time_field, type: Time, default: -> { Time.now }
|
109
109
|
def add_property(name, *args)
|
110
|
-
options = args[-1].is_a?(Hash) ? args[-1] : {}
|
110
|
+
options = args[-1].is_a?(Hash) ? args[-1].slice(:default, :type) : {}
|
111
111
|
options[:type] = args[0] if args[0] && !(args[0].is_a?(Hash) && args[0].key?(:default))
|
112
112
|
properties[name.to_s] = options
|
113
113
|
create_accessors(name, options)
|
data/lib/data_steroid/version.rb
CHANGED