shale-builder 0.6.6 → 0.7.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 +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +19 -0
- data/lib/shale/builder/nested_validations.rb +16 -1
- data/lib/shale/builder/version.rb +1 -1
- 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: 47c398fb41a4f4a4b2739aa542a822e2979c36ed7373dede2551d639116b2c8a
|
|
4
|
+
data.tar.gz: 39c4d99b27828c05d9bf92afe73622e681ea53cf8d5350b6ea6fb13358f46554
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bba9c31eec3c19efa1866a9295b7c625410e600fd4051fecfd4eb150c26d2b955dcbb64117eb6d0d78783b134d4f203a7c225e5a97a1c247abbcbbf1e48652ee
|
|
7
|
+
data.tar.gz: 27e186c186770c0c5fd7e6f62efb141b2ba1d71f26ec8eb127659253c7ce7f936e0cd56f325050132e4e96ea74471df16804d7b61704852d32c8154ca93b8fd0
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@ 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.7.1] - 2025-10-17
|
|
9
|
+
|
|
10
|
+
[Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.7.0...v0.7.1)
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
- Make `Shale::Builder::NestedValidations::nested_attr_name_separator` inheritable
|
|
14
|
+
|
|
15
|
+
## [0.7.0] - 2025-10-17
|
|
16
|
+
|
|
17
|
+
[Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.6.4...v0.7.0)
|
|
18
|
+
|
|
19
|
+
### Changes
|
|
20
|
+
- Add `Shale::Builder::NestedValidations::nested_attr_name_separator` that lets users customise the nested attribute name separator in validation errors
|
|
21
|
+
|
|
8
22
|
## [0.6.4] - 2025-10-16
|
|
9
23
|
|
|
10
24
|
[Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.6.3...v0.6.4)
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -263,6 +263,25 @@ obj.errors.messages #=> {cvv_code: ["can't be blank"], "amount.value": ["can't b
|
|
|
263
263
|
|
|
264
264
|
You MUST include `ActiveModel::Validations` before `Shale::Builder::NestedValidations`.
|
|
265
265
|
|
|
266
|
+
The attribute name separator can be changed like so:
|
|
267
|
+
|
|
268
|
+
```rb
|
|
269
|
+
class TransactionType < ::Shale::Mapper
|
|
270
|
+
self.nested_attr_name_separator = ':'
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
obj = TransactionType.build do |t|
|
|
275
|
+
t.amount do |a|
|
|
276
|
+
a.currency = 'USD'
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
obj.valid? #=> false
|
|
281
|
+
obj.errors #=> #<ActiveModel::Errors [#<ActiveModel::Error attribute=cvv_code, type=blank, options={}>, #<ActiveModel::NestedError attribute=amount:value, type=blank, options={}>]>
|
|
282
|
+
obj.errors.messages #=> {cvv_code: ["can't be blank"], "amount:value": ["can't be blank"]}
|
|
283
|
+
```
|
|
284
|
+
|
|
266
285
|
### Recording Assigned Attributes
|
|
267
286
|
|
|
268
287
|
There is an additional module `Shale::Builder::AssignedAttributes` that provides
|
|
@@ -18,6 +18,19 @@ module Shale
|
|
|
18
18
|
module ClassMethods
|
|
19
19
|
extend T::Sig
|
|
20
20
|
|
|
21
|
+
#: String
|
|
22
|
+
attr_writer :nested_attr_name_separator
|
|
23
|
+
|
|
24
|
+
#: -> String
|
|
25
|
+
def nested_attr_name_separator
|
|
26
|
+
return @nested_attr_name_separator if @nested_attr_name_separator
|
|
27
|
+
|
|
28
|
+
s = superclass
|
|
29
|
+
return @nested_attr_name_separator = s.nested_attr_name_separator if s < NestedValidations
|
|
30
|
+
|
|
31
|
+
@nested_attr_name_separator = '.'
|
|
32
|
+
end
|
|
33
|
+
|
|
21
34
|
sig { returns(T::Hash[Symbol, Shale::Attribute]) }
|
|
22
35
|
def validatable_attributes
|
|
23
36
|
@validatable_attributes ||= attributes.select do |_, val|
|
|
@@ -31,6 +44,8 @@ module Shale
|
|
|
31
44
|
def valid?
|
|
32
45
|
result = super
|
|
33
46
|
errlist = errors
|
|
47
|
+
klass = self.class #: as untyped
|
|
48
|
+
separator = klass.nested_attr_name_separator
|
|
34
49
|
|
|
35
50
|
attrs = T.unsafe(self).class.validatable_attributes
|
|
36
51
|
attrs.each_key do |name|
|
|
@@ -40,7 +55,7 @@ module Shale
|
|
|
40
55
|
|
|
41
56
|
result = false
|
|
42
57
|
val.errors.each do |err|
|
|
43
|
-
errlist.import(err, attribute: "#{name}
|
|
58
|
+
errlist.import(err, attribute: "#{name}#{separator}#{err.attribute}")
|
|
44
59
|
end
|
|
45
60
|
end
|
|
46
61
|
|