shale-builder 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/shale/builder/version.rb +1 -1
- data/lib/tapioca/dsl/compilers/shale.rb +64 -40
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1b61d4f6f883e6c38a5e30350fd069a965af0768a3025b8dcaee86c15e12b33
|
4
|
+
data.tar.gz: 6f7cc4a30ea88549050d3054451b37caae4c25bbd0fed6593b40d481bab6bd7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a2dd0016276064808485498d44784e36f8f408332d77aa1f8a2b33c73e0388d27eb89ddfa0a7199faa406d7f62943630f72dcbc562d9c09989aa9e6b342ae12
|
7
|
+
data.tar.gz: e17f0dd84c2d654fce94acbd803e9984992abe72dfe6748865762faadbbd9d4ec45f333c4efc50338084b4980b640cfa005e0064b86528ee7a06bf30619f7025
|
data/Gemfile.lock
CHANGED
@@ -37,33 +37,40 @@ module Tapioca
|
|
37
37
|
attribute_names = constant.attributes.keys.sort
|
38
38
|
attribute_names.each do |attribute_name|
|
39
39
|
attribute = T.let(constant.attributes[attribute_name], ::Shale::Attribute)
|
40
|
-
|
41
|
-
type = nilable_type
|
42
|
-
if attribute.collection?
|
43
|
-
type = "T.nilable(T::Array[#{non_nilable_type}])"
|
44
|
-
end
|
40
|
+
return_type, nilable = shale_type_to_sorbet_return_type(attribute)
|
45
41
|
comments = T.let([], T::Array[RBI::Comment])
|
46
42
|
if shale_builder_defined? && attribute.doc
|
47
43
|
comments << RBI::Comment.new(T.must(attribute.doc))
|
48
44
|
end
|
49
45
|
|
46
|
+
if attribute.collection?
|
47
|
+
getter_without_block_type = "T.nilable(T::Array[#{return_type}])"
|
48
|
+
elsif nilable
|
49
|
+
getter_without_block_type = "T.nilable(#{return_type})"
|
50
|
+
else
|
51
|
+
getter_without_block_type = return_type.to_s
|
52
|
+
end
|
53
|
+
|
50
54
|
if has_shale_builder && attribute.type < ::Shale::Mapper
|
51
|
-
generate_mapper_getter(mod, attribute.name,
|
55
|
+
generate_mapper_getter(mod, attribute.name, return_type, getter_without_block_type, comments)
|
52
56
|
else
|
53
|
-
mod.create_method(attribute.name, return_type:
|
57
|
+
mod.create_method(attribute.name, return_type: getter_without_block_type, comments: comments)
|
54
58
|
end
|
55
59
|
|
56
|
-
|
57
|
-
type = nilable_type
|
60
|
+
setter_type, nilable = shale_type_to_sorbet_setter_type(attribute)
|
58
61
|
if attribute.collection?
|
59
|
-
|
62
|
+
setter_type_str = "T.nilable(T::Array[#{setter_type}])"
|
63
|
+
elsif nilable
|
64
|
+
setter_type_str = "T.nilable(#{setter_type})"
|
65
|
+
else
|
66
|
+
setter_type_str = setter_type.to_s
|
60
67
|
end
|
61
68
|
|
62
69
|
# setter
|
63
70
|
mod.create_method(
|
64
71
|
"#{attribute.name}=",
|
65
|
-
parameters: [create_param('value', type:
|
66
|
-
return_type:
|
72
|
+
parameters: [create_param('value', type: setter_type_str)],
|
73
|
+
return_type: setter_type_str,
|
67
74
|
comments: comments,
|
68
75
|
)
|
69
76
|
end
|
@@ -75,24 +82,25 @@ module Tapioca
|
|
75
82
|
params(
|
76
83
|
mod: RBI::Scope,
|
77
84
|
method_name: String,
|
78
|
-
type:
|
79
|
-
|
85
|
+
type: Object,
|
86
|
+
getter_without_block_type: String,
|
80
87
|
comments: T::Array[RBI::Comment],
|
81
88
|
).void
|
82
89
|
end
|
83
|
-
def generate_mapper_getter(mod, method_name, type,
|
90
|
+
def generate_mapper_getter(mod, method_name, type, getter_without_block_type, comments)
|
84
91
|
if mod.respond_to?(:create_sig)
|
85
92
|
# for tapioca < 0.16.0
|
86
93
|
sigs = T.let([], T::Array[RBI::Sig])
|
94
|
+
|
87
95
|
# simple getter
|
88
96
|
sigs << mod.create_sig(
|
89
97
|
parameters: { block: 'NilClass' },
|
90
|
-
return_type:
|
98
|
+
return_type: getter_without_block_type,
|
91
99
|
)
|
92
100
|
# getter with block
|
93
101
|
sigs << mod.create_sig(
|
94
|
-
parameters: { block: "T.proc.params(arg0: #{
|
95
|
-
return_type:
|
102
|
+
parameters: { block: "T.proc.params(arg0: #{type}).void" },
|
103
|
+
return_type: type.to_s
|
96
104
|
)
|
97
105
|
mod.create_method_with_sigs(
|
98
106
|
method_name,
|
@@ -107,12 +115,12 @@ module Tapioca
|
|
107
115
|
|
108
116
|
method.add_sig do |sig|
|
109
117
|
sig.add_param('block', 'NilClass')
|
110
|
-
sig.return_type =
|
118
|
+
sig.return_type = getter_without_block_type
|
111
119
|
end
|
112
120
|
|
113
121
|
method.add_sig do |sig|
|
114
|
-
sig.add_param('block', "T.proc.params(arg0: #{
|
115
|
-
sig.return_type =
|
122
|
+
sig.add_param('block', "T.proc.params(arg0: #{type}).void")
|
123
|
+
sig.return_type = type.to_s
|
116
124
|
end
|
117
125
|
end
|
118
126
|
end
|
@@ -130,7 +138,22 @@ module Tapioca
|
|
130
138
|
sig { returns(T::Boolean) }
|
131
139
|
def shale_builder_defined? = Boolean(defined?(::Shale::Builder))
|
132
140
|
|
133
|
-
|
141
|
+
# Maps Shale return types to Sorbet types
|
142
|
+
SHALE_RETURN_TYPES_MAP = T.let(
|
143
|
+
{
|
144
|
+
::Shale::Type::Value => Object,
|
145
|
+
::Shale::Type::String => String,
|
146
|
+
::Shale::Type::Float => Float,
|
147
|
+
::Shale::Type::Integer => Integer,
|
148
|
+
::Shale::Type::Time => Time,
|
149
|
+
::Shale::Type::Date => Date,
|
150
|
+
::Shale::Type::Boolean => T::Boolean,
|
151
|
+
}.freeze,
|
152
|
+
T::Hash[Class, Object],
|
153
|
+
)
|
154
|
+
|
155
|
+
# Maps Shale setter types to Sorbet types
|
156
|
+
SHALE_SETTER_TYPES_MAP = T.let(
|
134
157
|
{
|
135
158
|
::Shale::Type::Value => Object,
|
136
159
|
::Shale::Type::String => String,
|
@@ -138,46 +161,47 @@ module Tapioca
|
|
138
161
|
::Shale::Type::Integer => Integer,
|
139
162
|
::Shale::Type::Time => Time,
|
140
163
|
::Shale::Type::Date => Date,
|
164
|
+
::Shale::Type::Boolean => Object,
|
141
165
|
}.freeze,
|
142
|
-
T::Hash[Class,
|
166
|
+
T::Hash[Class, Object],
|
143
167
|
)
|
144
168
|
|
145
|
-
sig { params(attribute: ::Shale::Attribute).returns([
|
169
|
+
sig { params(attribute: ::Shale::Attribute).returns([Object, T::Boolean]) }
|
146
170
|
def shale_type_to_sorbet_return_type(attribute)
|
147
|
-
return_type =
|
171
|
+
return_type = SHALE_RETURN_TYPES_MAP[attribute.type]
|
148
172
|
return complex_shale_type_to_sorbet_return_type(attribute) unless return_type
|
149
|
-
return
|
173
|
+
return return_type, false if attribute.collection? || return_type.is_a?(Module) && attribute.default.is_a?(return_type)
|
150
174
|
|
151
|
-
[
|
175
|
+
[return_type, true]
|
152
176
|
end
|
153
177
|
|
154
|
-
sig { params(attribute: ::Shale::Attribute).returns([
|
178
|
+
sig { params(attribute: ::Shale::Attribute).returns([Object, T::Boolean]) }
|
155
179
|
def complex_shale_type_to_sorbet_return_type(attribute)
|
156
|
-
return
|
180
|
+
return attribute.type, true unless attribute.type.respond_to?(:return_type)
|
157
181
|
|
158
182
|
return_type_string = attribute.type.return_type.to_s
|
159
|
-
[return_type_string,
|
183
|
+
[return_type_string, false]
|
160
184
|
end
|
161
185
|
|
162
|
-
sig { params(attribute: ::Shale::Attribute).returns([
|
186
|
+
sig { params(attribute: ::Shale::Attribute).returns([Object, T::Boolean]) }
|
163
187
|
def shale_type_to_sorbet_setter_type(attribute)
|
164
|
-
setter_type =
|
188
|
+
setter_type = SHALE_SETTER_TYPES_MAP[attribute.type]
|
165
189
|
return complex_shale_type_to_sorbet_setter_type(attribute) unless setter_type
|
166
|
-
return
|
190
|
+
return setter_type, false if attribute.collection? || setter_type.is_a?(Module) && attribute.default.is_a?(setter_type)
|
167
191
|
|
168
|
-
[
|
192
|
+
[setter_type, true]
|
169
193
|
end
|
170
194
|
|
171
|
-
sig { params(attribute: ::Shale::Attribute).returns([
|
195
|
+
sig { params(attribute: ::Shale::Attribute).returns([Object, T::Boolean]) }
|
172
196
|
def complex_shale_type_to_sorbet_setter_type(attribute)
|
173
197
|
if attribute.type.respond_to?(:setter_type)
|
174
|
-
setter_type_string = attribute.type.setter_type
|
175
|
-
[setter_type_string,
|
198
|
+
setter_type_string = attribute.type.setter_type
|
199
|
+
[setter_type_string, false]
|
176
200
|
elsif attribute.type.respond_to?(:return_type)
|
177
|
-
return_type_string = attribute.type.return_type
|
178
|
-
[return_type_string,
|
201
|
+
return_type_string = attribute.type.return_type
|
202
|
+
[return_type_string, false]
|
179
203
|
else
|
180
|
-
[
|
204
|
+
[attribute.type, true]
|
181
205
|
end
|
182
206
|
end
|
183
207
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shale-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Drewniak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: booleans
|