shale-builder 0.2.1 → 0.2.3
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 +102 -47
- 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: 01baf7e6e2a1bb3af915935d777089427a91fb25bf238bb1103fe7be133bea47
|
4
|
+
data.tar.gz: 7bb534cd32cf4681d90f25658c4bd659e22f1173d21434f06e39997cfb12188f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11ea61b420ba7fd7c24412e570344b5e1f57a4385f33884c2c0ad6118f5856d4d45a58903872d0c10c1c28af8f3f5f3d9481875817fb102f0bc135159f635efa
|
7
|
+
data.tar.gz: 2fe221a51291db87700f2a0d5e5777924c28d9e93527d3da8f9f0548592a9bfc5d5ae1d91819348c559d8bfcae088b80aa0dd36e9b14627f3df40aaff54c4b30
|
data/Gemfile.lock
CHANGED
@@ -37,49 +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
|
-
|
52
|
-
# simple getter
|
53
|
-
sigs << klass.create_sig(
|
54
|
-
parameters: { block: 'NilClass' },
|
55
|
-
return_type: type,
|
56
|
-
)
|
57
|
-
# getter with block
|
58
|
-
sigs << klass.create_sig(
|
59
|
-
parameters: { block: "T.proc.params(arg0: #{non_nilable_type}).void" },
|
60
|
-
return_type: non_nilable_type
|
61
|
-
)
|
62
|
-
mod.create_method_with_sigs(
|
63
|
-
attribute.name,
|
64
|
-
sigs: sigs,
|
65
|
-
comments: comments,
|
66
|
-
parameters: [RBI::BlockParam.new('block')],
|
67
|
-
)
|
55
|
+
generate_mapper_getter(mod, attribute.name, return_type, getter_without_block_type, comments)
|
68
56
|
else
|
69
|
-
mod.create_method(attribute.name, return_type:
|
57
|
+
mod.create_method(attribute.name, return_type: getter_without_block_type, comments: comments)
|
70
58
|
end
|
71
59
|
|
72
|
-
|
73
|
-
type = nilable_type
|
60
|
+
setter_type, nilable = shale_type_to_sorbet_setter_type(attribute)
|
74
61
|
if attribute.collection?
|
75
|
-
|
62
|
+
setter_type = "T.nilable(T::Array[#{return_type}])"
|
63
|
+
elsif nilable
|
64
|
+
setter_type = "T.nilable(#{return_type})"
|
65
|
+
else
|
66
|
+
setter_type = return_type.to_s
|
76
67
|
end
|
77
68
|
|
78
69
|
# setter
|
79
70
|
mod.create_method(
|
80
71
|
"#{attribute.name}=",
|
81
|
-
parameters: [create_param('value', type:
|
82
|
-
return_type:
|
72
|
+
parameters: [create_param('value', type: setter_type)],
|
73
|
+
return_type: setter_type,
|
83
74
|
comments: comments,
|
84
75
|
)
|
85
76
|
end
|
@@ -87,6 +78,54 @@ module Tapioca
|
|
87
78
|
|
88
79
|
end
|
89
80
|
|
81
|
+
sig do
|
82
|
+
params(
|
83
|
+
mod: RBI::Scope,
|
84
|
+
method_name: String,
|
85
|
+
type: Object,
|
86
|
+
getter_without_block_type: String,
|
87
|
+
comments: T::Array[RBI::Comment],
|
88
|
+
).void
|
89
|
+
end
|
90
|
+
def generate_mapper_getter(mod, method_name, type, getter_without_block_type, comments)
|
91
|
+
if mod.respond_to?(:create_sig)
|
92
|
+
# for tapioca < 0.16.0
|
93
|
+
sigs = T.let([], T::Array[RBI::Sig])
|
94
|
+
|
95
|
+
# simple getter
|
96
|
+
sigs << mod.create_sig(
|
97
|
+
parameters: { block: 'NilClass' },
|
98
|
+
return_type: getter_without_block_type,
|
99
|
+
)
|
100
|
+
# getter with block
|
101
|
+
sigs << mod.create_sig(
|
102
|
+
parameters: { block: "T.proc.params(arg0: #{type}).void" },
|
103
|
+
return_type: type.to_s
|
104
|
+
)
|
105
|
+
mod.create_method_with_sigs(
|
106
|
+
method_name,
|
107
|
+
sigs: sigs,
|
108
|
+
comments: comments,
|
109
|
+
parameters: [RBI::BlockParam.new('block')],
|
110
|
+
)
|
111
|
+
else
|
112
|
+
# for tapioca >= 0.16.0
|
113
|
+
mod.create_method(method_name, comments: comments) do |method|
|
114
|
+
method.add_block_param('block')
|
115
|
+
|
116
|
+
method.add_sig do |sig|
|
117
|
+
sig.add_param('block', 'NilClass')
|
118
|
+
sig.return_type = getter_without_block_type
|
119
|
+
end
|
120
|
+
|
121
|
+
method.add_sig do |sig|
|
122
|
+
sig.add_param('block', "T.proc.params(arg0: #{type}).void")
|
123
|
+
sig.return_type = type.to_s
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
90
129
|
private
|
91
130
|
|
92
131
|
sig { params(klass: Class).returns(T.nilable(T::Boolean)) }
|
@@ -99,7 +138,22 @@ module Tapioca
|
|
99
138
|
sig { returns(T::Boolean) }
|
100
139
|
def shale_builder_defined? = Boolean(defined?(::Shale::Builder))
|
101
140
|
|
102
|
-
|
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(
|
103
157
|
{
|
104
158
|
::Shale::Type::Value => Object,
|
105
159
|
::Shale::Type::String => String,
|
@@ -107,46 +161,47 @@ module Tapioca
|
|
107
161
|
::Shale::Type::Integer => Integer,
|
108
162
|
::Shale::Type::Time => Time,
|
109
163
|
::Shale::Type::Date => Date,
|
164
|
+
::Shale::Type::Boolean => Object,
|
110
165
|
}.freeze,
|
111
|
-
T::Hash[Class,
|
166
|
+
T::Hash[Class, Object],
|
112
167
|
)
|
113
168
|
|
114
|
-
sig { params(attribute: ::Shale::Attribute).returns([
|
169
|
+
sig { params(attribute: ::Shale::Attribute).returns([Object, T::Boolean]) }
|
115
170
|
def shale_type_to_sorbet_return_type(attribute)
|
116
|
-
return_type =
|
171
|
+
return_type = SHALE_RETURN_TYPES_MAP[attribute.type]
|
117
172
|
return complex_shale_type_to_sorbet_return_type(attribute) unless return_type
|
118
|
-
return
|
173
|
+
return return_type, false if attribute.collection? || return_type.is_a?(Module) && attribute.default.is_a?(return_type)
|
119
174
|
|
120
|
-
[
|
175
|
+
[return_type, true]
|
121
176
|
end
|
122
177
|
|
123
|
-
sig { params(attribute: ::Shale::Attribute).returns([
|
178
|
+
sig { params(attribute: ::Shale::Attribute).returns([Object, T::Boolean]) }
|
124
179
|
def complex_shale_type_to_sorbet_return_type(attribute)
|
125
|
-
return
|
180
|
+
return attribute.type, true unless attribute.type.respond_to?(:return_type)
|
126
181
|
|
127
182
|
return_type_string = attribute.type.return_type.to_s
|
128
|
-
[return_type_string,
|
183
|
+
[return_type_string, false]
|
129
184
|
end
|
130
185
|
|
131
|
-
sig { params(attribute: ::Shale::Attribute).returns([
|
186
|
+
sig { params(attribute: ::Shale::Attribute).returns([Object, T::Boolean]) }
|
132
187
|
def shale_type_to_sorbet_setter_type(attribute)
|
133
|
-
setter_type =
|
188
|
+
setter_type = SHALE_SETTER_TYPES_MAP[attribute.type]
|
134
189
|
return complex_shale_type_to_sorbet_setter_type(attribute) unless setter_type
|
135
|
-
return
|
190
|
+
return setter_type, false if attribute.collection? || setter_type.is_a?(Module) && attribute.default.is_a?(setter_type)
|
136
191
|
|
137
|
-
[
|
192
|
+
[setter_type, true]
|
138
193
|
end
|
139
194
|
|
140
|
-
sig { params(attribute: ::Shale::Attribute).returns([
|
195
|
+
sig { params(attribute: ::Shale::Attribute).returns([Object, T::Boolean]) }
|
141
196
|
def complex_shale_type_to_sorbet_setter_type(attribute)
|
142
197
|
if attribute.type.respond_to?(:setter_type)
|
143
|
-
setter_type_string = attribute.type.setter_type
|
144
|
-
[setter_type_string,
|
198
|
+
setter_type_string = attribute.type.setter_type
|
199
|
+
[setter_type_string, false]
|
145
200
|
elsif attribute.type.respond_to?(:return_type)
|
146
|
-
return_type_string = attribute.type.return_type
|
147
|
-
[return_type_string,
|
201
|
+
return_type_string = attribute.type.return_type
|
202
|
+
[return_type_string, false]
|
148
203
|
else
|
149
|
-
[
|
204
|
+
[attribute.type, true]
|
150
205
|
end
|
151
206
|
end
|
152
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.3
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: booleans
|