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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/lib/shale/attribute.rb +7 -0
- data/lib/shale/builder/assigned_attributes.rb +8 -0
- data/lib/shale/builder/version.rb +1 -1
- data/lib/shale/builder.rb +56 -8
- 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: deda7a499a25b163757c80e48d20b064347d1060e2ddf572a3d0870887c4010a
|
|
4
|
+
data.tar.gz: f1832b6e591d22a5af55d77c97d7460098e970c298ed50d6479eb038b044ba74
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
data/lib/shale/attribute.rb
CHANGED
|
@@ -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]
|
data/lib/shale/builder.rb
CHANGED
|
@@ -169,16 +169,44 @@ module Shale
|
|
|
169
169
|
RUBY
|
|
170
170
|
end
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
181
|
-
|
|
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
|
|