shale-builder 0.7.0 → 0.8.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 +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +19 -0
- data/lib/shale/builder/nested_validations.rb +39 -12
- 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: 1bc4050027c07ff6a3bf24b27df89131835ebe1cf9beb9d53bc1277809616a27
|
|
4
|
+
data.tar.gz: 109df45cbb2687a06e08fcc9baa153c2a813410cc009a730c1453672031e0387
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0b363fdf655cb8aec7a996f9dee375e8116aaed816a28e112acdaba2413cdbc902f32915f8670cffc92caec08042b8a0bd90c4e80c996d58ee7b9a0bcff07f95
|
|
7
|
+
data.tar.gz: 93ffb3fa8e767cab76bb9ad84492fd4fb581b1345fe2614964f4f63a5ba4b107c5928892c16edb8794288d49bcd9b8097321be904da7628d09ec9934c2709c00
|
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.8.0] - 2025-10-24
|
|
9
|
+
|
|
10
|
+
[Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.7.1...v0.8.0)
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
- Add `Shale::Builder::NestedValidations#validatable_attribute_names`, `Shale::Builder::NestedValidations#nested_attr_name_separator`, `Shale::Builder::NestedValidations#import_errors`
|
|
14
|
+
|
|
15
|
+
## [0.7.1] - 2025-10-17
|
|
16
|
+
|
|
17
|
+
[Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.7.0...v0.7.1)
|
|
18
|
+
|
|
19
|
+
### Changes
|
|
20
|
+
- Make `Shale::Builder::NestedValidations::nested_attr_name_separator` inheritable
|
|
21
|
+
|
|
8
22
|
## [0.7.0] - 2025-10-17
|
|
9
23
|
|
|
10
24
|
[Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.6.4...v0.7.0)
|
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
|
|
@@ -23,47 +23,74 @@ module Shale
|
|
|
23
23
|
|
|
24
24
|
#: -> String
|
|
25
25
|
def nested_attr_name_separator
|
|
26
|
-
@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 = '.'
|
|
27
32
|
end
|
|
28
33
|
|
|
29
|
-
|
|
34
|
+
#: -> Hash[Symbol, Shale::Attribute]
|
|
30
35
|
def validatable_attributes
|
|
31
36
|
@validatable_attributes ||= attributes.select do |_, val|
|
|
32
37
|
val.validatable?
|
|
33
38
|
end
|
|
34
39
|
end
|
|
40
|
+
|
|
41
|
+
#: -> Array[Symbol]
|
|
42
|
+
def validatable_attribute_names
|
|
43
|
+
validatable_attribute_names.keys
|
|
44
|
+
end
|
|
35
45
|
end
|
|
36
46
|
mixes_in_class_methods ClassMethods
|
|
37
47
|
|
|
38
|
-
|
|
48
|
+
#: -> Array[Symbol]
|
|
49
|
+
def validatable_attribute_names
|
|
50
|
+
self.class.validatable_attribute_names
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#: -> String
|
|
54
|
+
def nested_attr_name_separator
|
|
55
|
+
self.class.nested_attr_name_separator
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
#: -> bool
|
|
39
59
|
def valid?
|
|
40
60
|
result = super
|
|
41
|
-
errlist = errors
|
|
42
|
-
klass = self.class #: as untyped
|
|
43
|
-
separator = klass.nested_attr_name_separator
|
|
44
61
|
|
|
45
|
-
|
|
46
|
-
|
|
62
|
+
validatable_attribute_names.each_key do |name|
|
|
63
|
+
next unless name
|
|
64
|
+
|
|
47
65
|
val = public_send(name)
|
|
48
66
|
next unless val
|
|
49
67
|
next if val.valid?
|
|
50
68
|
|
|
51
69
|
result = false
|
|
52
|
-
val
|
|
53
|
-
errlist.import(err, attribute: "#{name}#{separator}#{err.attribute}")
|
|
54
|
-
end
|
|
70
|
+
import_errors(val)
|
|
55
71
|
end
|
|
56
72
|
|
|
57
73
|
result
|
|
58
74
|
end
|
|
59
75
|
|
|
76
|
+
#: (ActiveModel::Validations?) -> void
|
|
77
|
+
def import_errors(obj)
|
|
78
|
+
return unless obj
|
|
79
|
+
|
|
80
|
+
errlist = errors
|
|
81
|
+
separator = nested_attr_name_separator
|
|
82
|
+
obj.errors.each do |err|
|
|
83
|
+
errlist.import(err, attribute: "#{name}#{separator}#{err.attribute}")
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
60
87
|
end
|
|
61
88
|
end
|
|
62
89
|
end
|
|
63
90
|
|
|
64
91
|
module Shale
|
|
65
92
|
class Attribute # rubocop:disable Style/Documentation
|
|
66
|
-
|
|
93
|
+
#: -> bool
|
|
67
94
|
def validatable?
|
|
68
95
|
Boolean(type.is_a?(Class) && type < ::ActiveModel::Validations)
|
|
69
96
|
end
|