shale-builder 0.5.1 → 0.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5129b4e45147ec672d0e23aaf17ad57290bdc9f1f4a81b9d1756ebd44a738df3
4
- data.tar.gz: 0e47f511519fe4003622c862799ccd34e51bf61bba7bbce3ca6d8e81bdac95d8
3
+ metadata.gz: da23c125418576ee513aefaabf8cc5817b9be9308755347902a55d3b8833c08f
4
+ data.tar.gz: 76f3e943bea32652f01ecd0ea5d05565137a8b23b70c4edc386b87b534658e06
5
5
  SHA512:
6
- metadata.gz: 4682a5bf3469eec462ad9a191434bb761c633cf21117e2443dba85cefc4a2e2641104c4966cd113d76200b95954206b3292fc1182836b550a085cf4d144625c6
7
- data.tar.gz: 349e8086105a41ee0b5decb2ebbedcb810f7a331ae8b0e2b6a1bdab051eeafb9939e5d36f7d4b841062d7eab3269f85fb0b07d77eb63d3abfdae24ea9b774b7d
6
+ metadata.gz: 24737af006585825886b1588274f86da50a91f30303c89df4018dff232f59cb1d933d02a186346edb28b10455b14de8a72bf03e0623ef31225cf14f59866c15f
7
+ data.tar.gz: 7d6bb01e61849c64667cdc08b38b611b6cd70f1cae72cf736ab0e7e76dc427311dc345e2764abd42936c0d8c573bc7dd0e5a1b3901bfe23c977bcf509df3a7c3
data/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ 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.6.0] - 2025-10-16
9
+
10
+ [Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.5.1...v0.6.0)
11
+
12
+ ### Changes
13
+ - Add `Shale::Builder::mapper_attributes`, `Shale::Builder::mapper_attributes!`, `Shale::Builder::builder_attributes`, `Shale::Builder::builder_attributes!`
14
+ - Add `Shale::Builder#inject_context`
15
+
8
16
  ## [0.5.1] - 2025-10-15
9
17
 
10
18
  [Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.5.0...v0.5.1)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shale-builder (0.5.1)
4
+ shale-builder (0.6.0)
5
5
  booleans (>= 0.1)
6
6
  shale (< 2.0)
7
7
  sorbet-runtime (> 0.5)
@@ -38,5 +38,12 @@ module Shale
38
38
  def mapper?
39
39
  type.is_a?(Class) && type < Shale::Mapper
40
40
  end
41
+
42
+ # Returns `true` if the attribute is handled by a shale builder.
43
+ #
44
+ #: -> bool
45
+ def builder?
46
+ type.is_a?(Class) && type < Shale::Builder
47
+ end
41
48
  end
42
49
  end
@@ -59,6 +59,14 @@ module Shale
59
59
  end
60
60
  mixes_in_class_methods ClassMethods
61
61
 
62
+ def initialize(*args, **kwargs, &block)
63
+ super
64
+ @__initialized = true
65
+ end
66
+
67
+ #: bool?
68
+ attr_reader :__initialized
69
+
62
70
  # Returns a set of names of assigned shale attributes.
63
71
  #
64
72
  #: -> Set[Symbol]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Shale
4
4
  module Builder
5
- VERSION = '0.5.1'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
data/lib/shale/builder.rb CHANGED
@@ -169,16 +169,44 @@ module Shale
169
169
  RUBY
170
170
  end
171
171
 
172
- end
173
- mixes_in_class_methods(ClassMethods)
172
+ # Returns a hash of shale attributes that are handled by a shale mapper.
173
+ # The result gets memoized.
174
+ #
175
+ #: -> Hash[Symbol, Shale::Attribute]
176
+ def mapper_attributes
177
+ @mapper_attributes ||= mapper_attributes!
178
+ end
174
179
 
175
- def initialize(*args, **kwargs, &block)
176
- super
177
- @__initialized = true
178
- end
180
+ # Returns a hash of shale attributes that are handled by a shale mapper.
181
+ # Always constructs a new hash.
182
+ #
183
+ #: -> Hash[Symbol, Shale::Attribute]
184
+ def mapper_attributes!
185
+ attributes.select do |_, attr|
186
+ attr.mapper?
187
+ end
188
+ end
179
189
 
180
- #: bool?
181
- attr_reader :__initialized
190
+ # Returns a hash of shale attributes that are handled by a shale builder.
191
+ # The result gets memoized.
192
+ #
193
+ #: -> Hash[Symbol, Shale::Attribute]
194
+ def builder_attributes
195
+ @builder_attributes ||= builder_attributes!
196
+ end
197
+
198
+ # Returns a hash of shale attributes that are handled by a shale builder.
199
+ # Always constructs a new hash.
200
+ #
201
+ #: -> Hash[Symbol, Shale::Attribute]
202
+ def builder_attributes!
203
+ attributes.select do |_, attr|
204
+ attr.builder?
205
+ end
206
+ end
207
+
208
+ end
209
+ mixes_in_class_methods(ClassMethods)
182
210
 
183
211
  # Returns an array of shale values
184
212
  # that have been assigned.
@@ -191,6 +219,25 @@ module Shale
191
219
  end
192
220
  end
193
221
 
222
+ # Attempts to set the given attributes and values
223
+ # within this shale builder object and all of its sub-builders.
224
+ # Attributes that aren't defined are ignored.
225
+ #
226
+ #: (**untyped) -> void
227
+ def inject_context(**context)
228
+ context.each do |name, val|
229
+ try(:"#{name}=", val)
230
+ end
231
+
232
+ klass = self.class #: as untyped
233
+ klass.builder_attributes.each_key do |name|
234
+ val = public_send(name)
235
+ next unless val
236
+
237
+ val.inject_context(context)
238
+ end
239
+ end
240
+
194
241
  end
195
242
  end
196
243
 
@@ -40,6 +40,7 @@ module Tapioca
40
40
  attribute = constant.attributes[attribute_name] #: ::Shale::Attribute
41
41
  if (type = attribute.return_type)
42
42
  return_type = type
43
+ nilable = true
43
44
  else
44
45
  return_type, nilable = shale_type_to_sorbet_return_type(attribute)
45
46
  end
@@ -58,6 +59,7 @@ module Tapioca
58
59
 
59
60
  if (type = attribute.return_type || attribute.setter_type)
60
61
  setter_type = type
62
+ nilable = true
61
63
  else
62
64
  setter_type, nilable = shale_type_to_sorbet_setter_type(attribute)
63
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shale-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Drewniak