type_struct 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/type_struct.rb +1 -1
- data/lib/type_struct/generator.rb +26 -24
- data/lib/type_struct/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: cbecb2844975883551a46f903fbf34f9439e41b2
|
4
|
+
data.tar.gz: f58dee879f4b19b1d6af9881f69cca31d156f1c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7d605b64ed3a8c7a0c988acbddcb9236f51fd2e58b25f3ca040a1d7e9e2cd28cd3f013cf406e8dec0531bc7c329cb116494f2c2d9c3a32fe01c843e86156196
|
7
|
+
data.tar.gz: bbec831d29e3edcbbcd764e1dc462335f899d94c106ca45b6b6bf8f39c9cc66aadd70fc91bb3df89e838620310e35293d62d277dc7d0a20eafed9f6550a6f3fc
|
data/lib/type_struct.rb
CHANGED
@@ -64,7 +64,7 @@ class TypeStruct
|
|
64
64
|
module ClassMethods
|
65
65
|
def from_hash(arg)
|
66
66
|
unless h = Hash.try_convert(arg)
|
67
|
-
raise TypeError, "#{
|
67
|
+
raise TypeError, "no implicit conversion from #{arg} to Hash"
|
68
68
|
end
|
69
69
|
args = {}
|
70
70
|
errors = []
|
@@ -22,34 +22,36 @@ class TypeStruct
|
|
22
22
|
io = StringIO.new
|
23
23
|
io.puts "#{name} = TypeStruct.new("
|
24
24
|
h.each do |key, value|
|
25
|
-
|
26
|
-
when Array
|
27
|
-
if value.empty?
|
28
|
-
io.puts " #{key}: Array,"
|
29
|
-
else
|
30
|
-
type_struct = key.to_s.gsub(/s\z/, '').split('_').map(&:capitalize).join
|
31
|
-
parse(type_struct, value.first)
|
32
|
-
io.puts " #{key}: ArrayOf(#{type_struct}),"
|
33
|
-
end
|
34
|
-
when Hash
|
35
|
-
if value.empty?
|
36
|
-
io.puts " #{key}: Hash,"
|
37
|
-
else
|
38
|
-
type_struct = key.to_s.gsub(/e?s\z/, '').split('_').map(&:capitalize).join
|
39
|
-
parse(type_struct, value)
|
40
|
-
io.puts " #{key}: #{type_struct},"
|
41
|
-
end
|
42
|
-
when NilClass
|
43
|
-
io.puts " #{key}: Object,"
|
44
|
-
when TrueClass, FalseClass
|
45
|
-
io.puts " #{key}: TrueClass | FalseClass,"
|
46
|
-
else
|
47
|
-
io.puts " #{key}: #{value.class},"
|
48
|
-
end
|
25
|
+
io.puts " #{key}: #{parse_one(io, key, value)},"
|
49
26
|
end
|
50
27
|
io.puts ")"
|
51
28
|
@io.print io.string
|
52
29
|
@io.string
|
53
30
|
end
|
31
|
+
|
32
|
+
def parse_one(io, key, value)
|
33
|
+
case value
|
34
|
+
when Array
|
35
|
+
if value.empty?
|
36
|
+
"Array"
|
37
|
+
else
|
38
|
+
"ArrayOf(#{parse_one(io, key, value.first)})"
|
39
|
+
end
|
40
|
+
when Hash
|
41
|
+
if value.empty?
|
42
|
+
"Hash"
|
43
|
+
else
|
44
|
+
type_struct = key.to_s.gsub(/e?s\z/, '').split('_').map(&:capitalize).join
|
45
|
+
parse(type_struct, value)
|
46
|
+
type_struct
|
47
|
+
end
|
48
|
+
when NilClass
|
49
|
+
"Object"
|
50
|
+
when TrueClass, FalseClass
|
51
|
+
"TrueClass | FalseClass"
|
52
|
+
else
|
53
|
+
value.class.to_s
|
54
|
+
end
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
data/lib/type_struct/version.rb
CHANGED