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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17721f8a9d6290570bc704b98b9ac7c946c28783
4
- data.tar.gz: 8620ad7296bc271d28c2b7e7b9cd08f75ab3b6e4
3
+ metadata.gz: 53417f9ad796f3bdbadd248016ebb1aed623160c
4
+ data.tar.gz: 0a653553b55d4d333bc0be0d4d53d337beb7b7a5
5
5
  SHA512:
6
- metadata.gz: a4d0f4aade414dd0bcd7b3bb8c249b68050098274b6146c9b30df3b787e68b1a67ef3eee56579ccfd560543b7707cbf7c409332f648b0eade531ba68d7e47fa9
7
- data.tar.gz: 0bacfbb30a8bf7a9404be306048287ba4cae1f23ce25d96c3a5b9fcc690cb4590f0ba40b52edf2debd4f8e5145ec75be8315b862237587bfa7403f4bfa881ea0
6
+ metadata.gz: 2f2ffb6a2a38ea3577dc2352d017af7b57f0ba5a4ada604703c4b500859b0ccb5c18328801e3a11555c9c4fd93d8792b2dcb18178723e3daf61c0c018ea21ec6
7
+ data.tar.gz: 88e18912f12e341dc4427b015c6e594b9990e78f227d8cdc167ddf8f3d4f9d84b18089549d00546bc0d76bf1358b4de27670fc846c78478cf44e2beefa706af1
@@ -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
- if value_type.nil?
154
- value
155
- elsif value_type.ancestors.include?(Hashstructor)
156
- raise HashstructorError, "No hash provided for building a Hashstructor object." unless value.is_a?(Hash)
157
-
158
- value_type.new(value)
159
- else
160
- VALID_VALUE_TYPES[value_type].call(value)
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
@@ -1,4 +1,4 @@
1
1
  module Hashstructor
2
2
  # The gem version. As one does.
3
- VERSION = "1.0.5"
3
+ VERSION = "1.0.6"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashstructor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Ropple