shale-builder 0.5.2 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8991027b587aeafbed207ac9cd822e41afebdfa569c024f6ed76bae038ea30b5
4
- data.tar.gz: f61364b0035ff89ef1ad00daca3829fb1597600cd9a7c8d581e3a137984670d7
3
+ metadata.gz: deda7a499a25b163757c80e48d20b064347d1060e2ddf572a3d0870887c4010a
4
+ data.tar.gz: f1832b6e591d22a5af55d77c97d7460098e970c298ed50d6479eb038b044ba74
5
5
  SHA512:
6
- metadata.gz: 1a929606c8017a98f0c30a54728bcf2d64ee6effa155a60c4a337fcc48360b98b82456d29530e2bcbecf9a31ca04281e8932db706972215ab2a36e7c354eed4c
7
- data.tar.gz: 3b70d9301cb4633ee59c37f37afa9c0f977e3726914491d8632ec8f4c95b5b21f78882a290da7482c595bf8a603695ad758b04b8e6d5665a7414579701980e96
6
+ metadata.gz: 4fd7a5e43321bd1eea34faf4ddc8bdbd7c053338186f14fb65cf12d0358bb6cc775c10469ebe3cf1284db5144e3b8bd992e5c0ccd8fe7fee5bc29be146909e7c
7
+ data.tar.gz: 742ee5d778cb343050c0aa06e6896ca03ee1d355c3cd325aa81308e1d70e987c399a97fcb0e204105c30c6fc50ec9a7f0c5946d65af8799fc22b3b6943a70f3f
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.2)
4
+ shale-builder (0.6.1)
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.2'
5
+ VERSION = '0.6.1'
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,26 @@ 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
+ setter = :"#{name}="
230
+ public_send(setter, val) if respond_to?(setter)
231
+ end
232
+
233
+ klass = self.class #: as untyped
234
+ klass.builder_attributes.each_key do |name|
235
+ val = public_send(name)
236
+ next unless val
237
+
238
+ val.inject_context(context)
239
+ end
240
+ end
241
+
194
242
  end
195
243
  end
196
244
 
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.2
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Drewniak