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 +4 -4
- data/lib/hashstructor/instance_methods.rb +32 -17
- data/lib/hashstructor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25c3d81e055c0cca5478fee6bd9cf66e59eabf09
|
4
|
+
data.tar.gz: 94d08297f5e8d6542d0859ae60513b8ee16245d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
59
|
+
out_value = member.parse_single(raw_value)
|
45
60
|
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
55
|
-
|
69
|
+
out_value[key] = member.parse_single(v)
|
70
|
+
end
|
56
71
|
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
76
|
+
out_value = raw_value.map { |v| member.parse_single(v) }
|
62
77
|
|
63
|
-
|
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)
|
data/lib/hashstructor/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|