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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62411529ae4d443eb76c8e65ec081314decf3fc1
4
- data.tar.gz: 18398c63d48e66b1f7cb92f88a2e8369e0c2e707
3
+ metadata.gz: cbecb2844975883551a46f903fbf34f9439e41b2
4
+ data.tar.gz: f58dee879f4b19b1d6af9881f69cca31d156f1c2
5
5
  SHA512:
6
- metadata.gz: e2de24f4d580ed09776828a16d5b66779eeffa4edd5a99efc2b18ca1e698e97fb7107175e9cb99d92f1da752abbfd1dd277e42adf1e674acb4db7c25aeb9f372
7
- data.tar.gz: 9ecf7b2fddfabfb78b353b7f2999b4d7036aaefef259ee043bd683c994103c0028e9a983f2393b0cfe5320d7a47bcf2faa95645c3f488e5c80337685aa6a273e
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, "#{self}.from_hash only accept Hash got `#{h.class}'"
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
- case value
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
@@ -1,3 +1,3 @@
1
1
  class TypeStruct
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: type_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss