mangrove 0.22.0 → 0.23.0

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
  SHA256:
3
- metadata.gz: b103efd7003a037c53a885f2ee19899ba8643770237c11bee728f06054611be7
4
- data.tar.gz: 5e7557ab35bb32b8212b830ba5d06c6f32904cf2b40fd04de3f469770afb19d1
3
+ metadata.gz: c1fff1639273ef4d4926c8a962ccca0717601bf37b5358f2ba65d1d3dd6f30ea
4
+ data.tar.gz: beb11055a2c9fff7b68af66586a226b97fe53cec2d22fb67180f81d1613eb07c
5
5
  SHA512:
6
- metadata.gz: d8f487f7ccd5ce99225cb19108eed5e3f89d1fece9048bd589ad78f4179a07ce370d47a876a66e30a992661cee5f40f970e3d3544b2a53e32677d58c3a5294c1
7
- data.tar.gz: 1c3003bca763ff503c496f15d271d253a8510c33bdb74ade89708c91774d31fd0c0f29b06a89de4a3661ef4b1b8fa8e863f838d42b4a89aa7e02cca189abcfed
6
+ metadata.gz: 82a914cdda372923944b1ff69839cc46b7bc00e26b2aca4abe91308bbb7d40ac6ce2fe0959eb6a8ae0d4b09f029744d83f807fa6e2b4d1e4469fa4eba56edbc7
7
+ data.tar.gz: 4dc31bad6e1b504d1c175d787074d0e2623964bbeceeb292300e6c84103e5dc8917177e8d191060a759c28dae1eaf7ff4ab9fbb40557300f2630a5e1ea90c83b
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Mangrove
5
- VERSION = "0.22.0"
5
+ VERSION = "0.23.0"
6
6
  end
@@ -24,20 +24,24 @@ module Tapioca
24
24
  RBI::Helper.new("sealed")
25
25
  )
26
26
 
27
- variants = constant.constants.filter_map { |variant_name|
28
- maybe_variant = constant.const_get(variant_name, false)
27
+ variants = constant
28
+ .constants
29
+ .filter_map { |variant_name|
30
+ maybe_variant = constant.const_get(variant_name, false)
29
31
 
30
- if maybe_variant.instance_variable_defined?(:@__mangrove__enum_inner_type)
31
- maybe_variant
32
- end
33
- }
32
+ if maybe_variant.instance_variable_defined?(:@__mangrove__enum_inner_type)
33
+ maybe_variant
34
+ end
35
+ }
36
+ .sort_by { |variant| variant.name.to_s }
34
37
 
35
38
  inner_types = variants.map { |variant|
36
- inner_type = variant.instance_variable_get(:@__mangrove__enum_inner_type).to_s
39
+ inner_type = runtime_type_to_type_name(variant.instance_variable_get(:@__mangrove__enum_inner_type))
37
40
  constant_type.create_class(variant.name.gsub(/.*::/, ""), superclass_name: constant_type.fully_qualified_name) { |variant_type|
38
41
  variant_type.create_method("initialize", parameters: [create_param("inner", type: inner_type)], return_type: "void")
39
42
  variant_type.create_method("inner", return_type: inner_type)
40
43
  variant_type.create_method("as_super", return_type: constant.name.to_s)
44
+ variant_type.sort_nodes!
41
45
  }
42
46
 
43
47
  inner_type
@@ -45,8 +49,34 @@ module Tapioca
45
49
 
46
50
  constant_type.create_method("inner", return_type: "T.any(#{inner_types.join(", ")})")
47
51
  constant_type.create_method("as_super", return_type: constant.name.to_s)
52
+ constant_type.sort_nodes!
48
53
  }
49
54
  end
55
+
56
+ private
57
+
58
+ sig { params(runtime_type: T.untyped).returns(String) }
59
+ def runtime_type_to_type_name(runtime_type)
60
+ if runtime_type.is_a?(Array)
61
+ content = runtime_type.map { |inner|
62
+ runtime_type_to_type_name(inner)
63
+ }.join(", ")
64
+
65
+ "[#{content}]"
66
+ elsif runtime_type.is_a?(Hash)
67
+ content = runtime_type.map { |k, v|
68
+ unless k.is_a?(Symbol) || k.is_a?(String)
69
+ raise "shape key must be Symbol or String"
70
+ end
71
+
72
+ "#{k}: #{runtime_type_to_type_name(v)}"
73
+ }.join(", ")
74
+
75
+ "{ #{content} }"
76
+ else
77
+ runtime_type.to_s
78
+ end
79
+ end
50
80
  end
51
81
  end
52
82
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mangrove
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuma Murata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-21 00:00:00.000000000 Z
11
+ date: 2023-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-runtime