hashstructor 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hashstructor/instance_methods.rb +10 -4
- data/lib/hashstructor/member.rb +15 -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: 675a97fc95885219b7cdaa51ddd36f67a231c5d3
|
4
|
+
data.tar.gz: ca05c6be506989b23d5afb11fe912bbdd7c6914b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cda2a0d1e8f58565bab6a92fe0c6f488777667b04ba5af61e543af68b45a95d328ff5da609c3e60185bef37f58685cbdb11fa0930ad890af8c6439d9195eeb5
|
7
|
+
data.tar.gz: 0ae36d6db64cb120b4158b5c97d8f68123f8a2329df7ca9b61f644a0641a9169e4677be7a7b00112809bb5fdfb6b894d1b3dba9b2fb4dc45ea5a0416d06a9c0d
|
@@ -29,13 +29,19 @@ module Hashstructor
|
|
29
29
|
|
30
30
|
existing_members = partitioned_members[0]
|
31
31
|
missing_members = partitioned_members[1]
|
32
|
-
raise HashstructorError, "Missing required members: #{missing_members.map { |m| m.name }.join(", ")}" \
|
33
|
-
if missing_members.any? { |m| m.required }
|
34
32
|
|
35
|
-
missing_members.
|
33
|
+
partitioned_missing_members = missing_members.partition { |m| !m.required || (m.required && m.options[:default_value]) }
|
34
|
+
|
35
|
+
acceptable_missing_members = partitioned_missing_members[0]
|
36
|
+
unacceptable_missing_members = partitioned_missing_members[1]
|
37
|
+
|
38
|
+
raise HashstructorError, "Missing required members: #{unacceptable_missing_members.map { |m| m.name }.join(", ")}" \
|
39
|
+
unless unacceptable_missing_members.empty?
|
40
|
+
|
41
|
+
acceptable_missing_members.each do |member|
|
36
42
|
out_value = case member.member_type
|
37
43
|
when :normal
|
38
|
-
|
44
|
+
member.options[:default_value]
|
39
45
|
when :array
|
40
46
|
[]
|
41
47
|
when :set
|
data/lib/hashstructor/member.rb
CHANGED
@@ -95,6 +95,9 @@ module Hashstructor
|
|
95
95
|
raise HashstructorError, "'member_type' (#{member_type}) must be one of: [ #{VALID_MEMBER_TYPES.join(", ")} ]" \
|
96
96
|
unless VALID_MEMBER_TYPES.include?(member_type.to_sym)
|
97
97
|
|
98
|
+
raise HashstructorError, "'member_type' must be :normal to use 'default_value'." \
|
99
|
+
if member_type != :normal && options[:default_value]
|
100
|
+
|
98
101
|
@member_type = member_type.to_sym
|
99
102
|
|
100
103
|
raise HashstructorError, "'value_type' must be nil or a Class." \
|
@@ -106,17 +109,21 @@ module Hashstructor
|
|
106
109
|
|
107
110
|
@value_type = value_type
|
108
111
|
|
112
|
+
raise HashstructorError, "'required' must be true if 'default_value'" \
|
113
|
+
if !required && options[:default_value]
|
109
114
|
@required = required
|
110
115
|
|
116
|
+
|
117
|
+
|
111
118
|
case attr_kind
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
119
|
+
when nil
|
120
|
+
# do nothing
|
121
|
+
when :reader
|
122
|
+
klass.send(:attr_reader, @name)
|
123
|
+
when :accessor
|
124
|
+
klass.send(:attr_accessor, @name)
|
125
|
+
else
|
126
|
+
raise HashstructorError, "Unrecognized attr_kind: #{attr_kind}"
|
120
127
|
end
|
121
128
|
@attr_kind = attr_kind
|
122
129
|
end
|
data/lib/hashstructor/version.rb
CHANGED