Skip to content

Commit 83857d1

Browse files
committed
v0.8.0
1 parent 159fdaf commit 83857d1

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

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+
815
## [0.7.1] - 2025-10-17
916

1017
[Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.7.0...v0.7.1)

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
shale-builder (0.7.1)
4+
shale-builder (0.8.0)
55
booleans (>= 0.1)
66
shale (< 2.0)
77
sorbet-runtime (> 0.5)

lib/shale/builder/nested_validations.rb

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,66 @@ def nested_attr_name_separator
3131
@nested_attr_name_separator = '.'
3232
end
3333

34-
sig { returns(T::Hash[Symbol, Shale::Attribute]) }
34+
#: -> Hash[Symbol, Shale::Attribute]
3535
def validatable_attributes
3636
@validatable_attributes ||= attributes.select do |_, val|
3737
val.validatable?
3838
end
3939
end
40+
41+
#: -> Array[Symbol]
42+
def validatable_attribute_names
43+
validatable_attribute_names.keys
44+
end
4045
end
4146
mixes_in_class_methods ClassMethods
4247

43-
sig { returns(T::Boolean) }
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
4459
def valid?
4560
result = super
46-
errlist = errors
47-
klass = self.class #: as untyped
48-
separator = klass.nested_attr_name_separator
4961

50-
attrs = T.unsafe(self).class.validatable_attributes
51-
attrs.each_key do |name|
62+
validatable_attribute_names.each_key do |name|
63+
next unless name
64+
5265
val = public_send(name)
5366
next unless val
5467
next if val.valid?
5568

5669
result = false
57-
val.errors.each do |err|
58-
errlist.import(err, attribute: "#{name}#{separator}#{err.attribute}")
59-
end
70+
import_errors(val)
6071
end
6172

6273
result
6374
end
6475

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+
6587
end
6688
end
6789
end
6890

6991
module Shale
7092
class Attribute # rubocop:disable Style/Documentation
71-
sig { returns(T::Boolean) }
93+
#: -> bool
7294
def validatable?
7395
Boolean(type.is_a?(Class) && type < ::ActiveModel::Validations)
7496
end

lib/shale/builder/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module Shale
44
module Builder
5-
VERSION = '0.7.1'
5+
VERSION = '0.8.0'
66
end
77
end

0 commit comments

Comments
 (0)