shale-builder 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/lib/shale/attribute.rb +6 -0
- data/lib/shale/builder/version.rb +1 -1
- data/lib/shale/builder.rb +27 -6
- data/lib/tapioca/dsl/compilers/shale.rb +12 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5129b4e45147ec672d0e23aaf17ad57290bdc9f1f4a81b9d1756ebd44a738df3
|
|
4
|
+
data.tar.gz: 0e47f511519fe4003622c862799ccd34e51bf61bba7bbce3ca6d8e81bdac95d8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4682a5bf3469eec462ad9a191434bb761c633cf21117e2443dba85cefc4a2e2641104c4966cd113d76200b95954206b3292fc1182836b550a085cf4d144625c6
|
|
7
|
+
data.tar.gz: 349e8086105a41ee0b5decb2ebbedcb810f7a331ae8b0e2b6a1bdab051eeafb9939e5d36f7d4b841062d7eab3269f85fb0b07d77eb63d3abfdae24ea9b774b7d
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.5.1] - 2025-10-15
|
|
9
|
+
|
|
10
|
+
[Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.5.0...v0.5.1)
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
- Add `return_type` and `setter_type` overrides per attribute
|
|
14
|
+
|
|
8
15
|
## [0.5.0] - 2025-10-15
|
|
9
16
|
|
|
10
17
|
[Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.4.1...v0.5.0)
|
data/Gemfile.lock
CHANGED
data/lib/shale/attribute.rb
CHANGED
|
@@ -7,6 +7,12 @@ module Shale
|
|
|
7
7
|
class Attribute # rubocop:disable Style/Documentation
|
|
8
8
|
extend T::Sig
|
|
9
9
|
|
|
10
|
+
#: untyped
|
|
11
|
+
attr_accessor :setter_type
|
|
12
|
+
|
|
13
|
+
#: untyped
|
|
14
|
+
attr_accessor :return_type
|
|
15
|
+
|
|
10
16
|
# Contains the documentation comment for the shale attribute
|
|
11
17
|
# in a Ruby String.
|
|
12
18
|
#: String?
|
data/lib/shale/builder.rb
CHANGED
|
@@ -97,13 +97,34 @@ module Shale
|
|
|
97
97
|
sig { abstract.returns(T::Hash[Symbol, Shale::Attribute]) }
|
|
98
98
|
def attributes; end
|
|
99
99
|
|
|
100
|
-
#: (
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
#: (
|
|
101
|
+
#| String | Symbol name,
|
|
102
|
+
#| Class shale_mapper,
|
|
103
|
+
#| ?collection: bool,
|
|
104
|
+
#| ?default: Proc?,
|
|
105
|
+
#| ?doc: String?,
|
|
106
|
+
#| ?return_type: untyped,
|
|
107
|
+
#| ?setter_type: untyped,
|
|
108
|
+
#| **Object kwargs
|
|
109
|
+
#| ) ?{ -> void } -> void
|
|
110
|
+
def attribute(
|
|
111
|
+
name,
|
|
112
|
+
shale_mapper,
|
|
113
|
+
collection: false,
|
|
114
|
+
default: nil,
|
|
115
|
+
doc: nil,
|
|
116
|
+
return_type: nil,
|
|
117
|
+
setter_type: nil,
|
|
118
|
+
**kwargs,
|
|
119
|
+
&block
|
|
120
|
+
)
|
|
121
|
+
super(name, shale_mapper, collection:, default:, **kwargs, &block)
|
|
103
122
|
if (attr_def = attributes[name.to_sym])
|
|
104
123
|
attr_def.doc = doc
|
|
124
|
+
attr_def.return_type = return_type
|
|
125
|
+
attr_def.setter_type = setter_type
|
|
105
126
|
end
|
|
106
|
-
return unless
|
|
127
|
+
return unless shale_mapper < ::Shale::Mapper
|
|
107
128
|
|
|
108
129
|
if collection
|
|
109
130
|
@builder_methods_module.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
@@ -111,7 +132,7 @@ module Shale
|
|
|
111
132
|
return super unless block_given? # return super unless block_given?
|
|
112
133
|
#
|
|
113
134
|
arr = self.#{name} ||= [] # arr = self.clients ||= []
|
|
114
|
-
object = #{
|
|
135
|
+
object = #{shale_mapper}.new # object = Client.new
|
|
115
136
|
yield(object) # yield(object)
|
|
116
137
|
arr << object # arr << object
|
|
117
138
|
object # object
|
|
@@ -124,7 +145,7 @@ module Shale
|
|
|
124
145
|
def #{name} # def amount
|
|
125
146
|
return super unless block_given? # return super unless block_given?
|
|
126
147
|
#
|
|
127
|
-
object = #{
|
|
148
|
+
object = #{shale_mapper}.new # object = Amount.new
|
|
128
149
|
yield(object) # yield(object)
|
|
129
150
|
self.#{name} = object # self.amount = object
|
|
130
151
|
end # end
|
|
@@ -37,9 +37,13 @@ module Tapioca
|
|
|
37
37
|
# For each attribute defined in the class
|
|
38
38
|
attribute_names = constant.attributes.keys.sort
|
|
39
39
|
attribute_names.each do |attribute_name|
|
|
40
|
-
attribute =
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
attribute = constant.attributes[attribute_name] #: ::Shale::Attribute
|
|
41
|
+
if (type = attribute.return_type)
|
|
42
|
+
return_type = type
|
|
43
|
+
else
|
|
44
|
+
return_type, nilable = shale_type_to_sorbet_return_type(attribute)
|
|
45
|
+
end
|
|
46
|
+
comments = [] #: T::Array[RBI::Comment]
|
|
43
47
|
if shale_builder_defined? && attribute.doc
|
|
44
48
|
comments << RBI::Comment.new(T.must(attribute.doc))
|
|
45
49
|
end
|
|
@@ -52,7 +56,11 @@ module Tapioca
|
|
|
52
56
|
getter_without_block_type = return_type.to_s
|
|
53
57
|
end
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
if (type = attribute.return_type || attribute.setter_type)
|
|
60
|
+
setter_type = type
|
|
61
|
+
else
|
|
62
|
+
setter_type, nilable = shale_type_to_sorbet_setter_type(attribute)
|
|
63
|
+
end
|
|
56
64
|
if attribute.collection?
|
|
57
65
|
setter_type_str = "T.nilable(T::Array[#{setter_type}])"
|
|
58
66
|
elsif nilable
|