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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25c3d81e055c0cca5478fee6bd9cf66e59eabf09
4
- data.tar.gz: 94d08297f5e8d6542d0859ae60513b8ee16245d1
3
+ metadata.gz: 675a97fc95885219b7cdaa51ddd36f67a231c5d3
4
+ data.tar.gz: ca05c6be506989b23d5afb11fe912bbdd7c6914b
5
5
  SHA512:
6
- metadata.gz: c160223d4139c04f3e93d50511a4570480f4792d20bb256639033852fa70cfcb29505b7f8a220df4ddd7afb94d98badd9ffff2a4813dc179b6868b27ad75d864
7
- data.tar.gz: c0a65ffeca251df3d1ea9263a84de50087c80917dcf283ab84f3f1c105da64abfff473f30f5110d0d7a564d21627468521912d5ab01d69832218b14f239063fb
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.reject { |m| m.required }.each do |member|
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
- # already nil
44
+ member.options[:default_value]
39
45
  when :array
40
46
  []
41
47
  when :set
@@ -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
- when nil
113
- # do nothing
114
- when :reader
115
- klass.send(:attr_reader, @name)
116
- when :accessor
117
- klass.send(:attr_accessor, @name)
118
- else
119
- raise HashstructorError, "Unrecognized attr_kind: #{attr_kind}"
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
@@ -1,4 +1,4 @@
1
1
  module Hashstructor
2
2
  # The gem version. As one does.
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
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.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Ropple