Class: SmartCore::Validator::Errors
- Inherits:
-
Object
- Object
- SmartCore::Validator::Errors
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/smart_core/validator/errors.rb
Instance Method Summary collapse
- #[](attr_path) ⇒ Object
- #attribute_already_exists?(attr_path) ⇒ Boolean
- #freeze ⇒ Object
-
#initialize ⇒ Errors
constructor
A new instance of Errors.
- #safely_add!(attr_path:, error_code:) ⇒ Object
- #safely_merge!(attr_path:, errors_enum:) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Errors
Returns a new instance of Errors.
9 10 11 |
# File 'lib/smart_core/validator/errors.rb', line 9 def initialize self.errors_container = {} end |
Instance Method Details
#[](attr_path) ⇒ Object
22 23 24 |
# File 'lib/smart_core/validator/errors.rb', line 22 def [](attr_path) errors_container[attr_path.to_s] end |
#attribute_already_exists?(attr_path) ⇒ Boolean
34 35 36 |
# File 'lib/smart_core/validator/errors.rb', line 34 def attribute_already_exists?(attr_path) errors_container.key?(attr_path.to_s) end |
#freeze ⇒ Object
26 27 28 |
# File 'lib/smart_core/validator/errors.rb', line 26 def freeze super.tap { errors_container.transform_values(&:freeze) } end |
#safely_add!(attr_path:, error_code:) ⇒ Object
13 14 15 |
# File 'lib/smart_core/validator/errors.rb', line 13 def safely_add!(attr_path:, error_code:) errors_container[attr_path.to_s] ||= error_code end |
#safely_merge!(attr_path:, errors_enum:) ⇒ Object
17 18 19 20 |
# File 'lib/smart_core/validator/errors.rb', line 17 def safely_merge!(attr_path:, errors_enum:) errors_container[attr_path.to_s] ||= Set.new errors_container[attr_path.to_s].merge(errors_enum) end |
#to_h ⇒ Object
30 31 32 |
# File 'lib/smart_core/validator/errors.rb', line 30 def to_h errors_container.dup end |