hashstructor 1.0.0 → 1.0.1

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: 1c5ba11f6bea507eada8ffef440f9c0ab35335ba
4
- data.tar.gz: cfa2de7abfece15ca53d8814efc5a8d5699b9934
3
+ metadata.gz: 25c3d81e055c0cca5478fee6bd9cf66e59eabf09
4
+ data.tar.gz: 94d08297f5e8d6542d0859ae60513b8ee16245d1
5
5
  SHA512:
6
- metadata.gz: c9d4e04bfe0737b868d16c8cc99250f10a195c8492f5b652a86e731b0c79e0efe62280c0715a80925b7b6e79bf37c68ffe4a03b3c102bbf4e0d92ed1932f5109
7
- data.tar.gz: 7b50b74f329a59862be978b0657e1aa4bd4afa6cbbb0673ce01b11f07e354dc29bd9e4820dc4a6c7c70702d436a131f4b268e94fe87d7f869c975e9b754c4514
6
+ metadata.gz: c160223d4139c04f3e93d50511a4570480f4792d20bb256639033852fa70cfcb29505b7f8a220df4ddd7afb94d98badd9ffff2a4813dc179b6868b27ad75d864
7
+ data.tar.gz: c0a65ffeca251df3d1ea9263a84de50087c80917dcf283ab84f3f1c105da64abfff473f30f5110d0d7a564d21627468521912d5ab01d69832218b14f239063fb
@@ -32,35 +32,50 @@ module Hashstructor
32
32
  raise HashstructorError, "Missing required members: #{missing_members.map { |m| m.name }.join(", ")}" \
33
33
  if missing_members.any? { |m| m.required }
34
34
 
35
+ missing_members.reject { |m| m.required }.each do |member|
36
+ out_value = case member.member_type
37
+ when :normal
38
+ # already nil
39
+ when :array
40
+ []
41
+ when :set
42
+ Set.new
43
+ when :hash
44
+ {}
45
+ end
46
+
47
+ instance_variable_set("@#{member.name}", out_value)
48
+ end
49
+
35
50
  existing_members.each do |member|
36
51
  raw_value = hash[member.name] || hash[member.name.to_s]
37
52
  out_value = nil
38
53
 
39
54
  case member.member_type
40
- when :normal
41
- raise HashstructorError, "member '#{member.name}' expects a single value, got #{raw_value.class.name}." \
42
- if member.options[:no_collections] && raw_value.is_a?(Enumerable)
55
+ when :normal
56
+ raise HashstructorError, "member '#{member.name}' expects a single value, got #{raw_value.class.name}." \
57
+ if member.options[:no_collections] && raw_value.is_a?(Enumerable)
43
58
 
44
- out_value = member.parse_single(raw_value)
59
+ out_value = member.parse_single(raw_value)
45
60
 
46
- when :hash
47
- raise HashstructorError, "member '#{member.name}' expects a Hash, got #{raw_value.class.name}." \
48
- unless raw_value.is_a?(Hash)
61
+ when :hash
62
+ raise HashstructorError, "member '#{member.name}' expects a Hash, got #{raw_value.class.name}." \
63
+ unless raw_value.is_a?(Hash)
49
64
 
50
- out_value = {}
51
- raw_value.each_pair do |k, v|
52
- key = member.options[:string_keys] ? k.to_s : k.to_s.to_sym
65
+ out_value = {}
66
+ raw_value.each_pair do |k, v|
67
+ key = member.options[:string_keys] ? k.to_s : k.to_s.to_sym
53
68
 
54
- out_value[key] = member.parse_single(v)
55
- end
69
+ out_value[key] = member.parse_single(v)
70
+ end
56
71
 
57
- when :array, :set
58
- raise HashstructorError, "member '#{member.name}' expects an Enumerable, got #{raw_value.class.name}"\
59
- unless raw_value.is_a?(Enumerable)
72
+ when :array, :set
73
+ raise HashstructorError, "member '#{member.name}' expects an Enumerable, got #{raw_value.class.name}"\
74
+ unless raw_value.is_a?(Enumerable)
60
75
 
61
- out_value = raw_value.map { |v| member.parse_single(v) }
76
+ out_value = raw_value.map { |v| member.parse_single(v) }
62
77
 
63
- out_value = out_value.to_set if member.member_type == :set
78
+ out_value = out_value.to_set if member.member_type == :set
64
79
  end
65
80
 
66
81
  instance_variable_set("@#{member.name}", out_value)
@@ -1,4 +1,4 @@
1
1
  module Hashstructor
2
2
  # The gem version. As one does.
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashstructor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Ropple
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-22 00:00:00.000000000 Z
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler