hashstructor 1.0.5 → 1.0.6
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/hashstructor/member.rb +21 -8
- data/lib/hashstructor/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: 53417f9ad796f3bdbadd248016ebb1aed623160c
|
4
|
+
data.tar.gz: 0a653553b55d4d333bc0be0d4d53d337beb7b7a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f2ffb6a2a38ea3577dc2352d017af7b57f0ba5a4ada604703c4b500859b0ccb5c18328801e3a11555c9c4fd93d8792b2dcb18178723e3daf61c0c018ea21ec6
|
7
|
+
data.tar.gz: 88e18912f12e341dc4427b015c6e594b9990e78f227d8cdc167ddf8f3d4f9d84b18089549d00546bc0d76bf1358b4de27670fc846c78478cf44e2beefa706af1
|
data/lib/hashstructor/member.rb
CHANGED
@@ -132,6 +132,7 @@ module Hashstructor
|
|
132
132
|
if !required && options[:default_value]
|
133
133
|
@required = required
|
134
134
|
|
135
|
+
raise HashstructorError, "'validation' must be a Proc." unless options[:validation].nil? || options[:validation].is_a?(Proc)
|
135
136
|
|
136
137
|
|
137
138
|
case attr_kind
|
@@ -150,15 +151,27 @@ module Hashstructor
|
|
150
151
|
# Parses the passed-in value (always a single item; {InstanceMethods#hashstruct} handles
|
151
152
|
# the breaking down of arrays and hashes) and returns a value according to {#value_type}.
|
152
153
|
def parse_single(value)
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
154
|
+
retval =
|
155
|
+
if value_type.nil?
|
156
|
+
value
|
157
|
+
elsif value_type.ancestors.include?(Hashstructor)
|
158
|
+
raise HashstructorError, "No hash provided for building a Hashstructor object." unless value.is_a?(Hash)
|
159
|
+
|
160
|
+
value_type.new(value)
|
161
|
+
else
|
162
|
+
VALID_VALUE_TYPES[value_type].call(value)
|
163
|
+
end
|
164
|
+
|
165
|
+
if options[:validation]
|
166
|
+
errors = []
|
167
|
+
options[:validation].call(retval, errors)
|
168
|
+
|
169
|
+
if !errors.empty?
|
170
|
+
raise HashstructorError, "Validation failure for '#{name}': #{errors.join("; ")}"
|
171
|
+
end
|
161
172
|
end
|
173
|
+
|
174
|
+
retval
|
162
175
|
end
|
163
176
|
end
|
164
177
|
end
|
data/lib/hashstructor/version.rb
CHANGED