Class: Core::Boundary::Validator
- Inherits:
-
Object
- Object
- Core::Boundary::Validator
- Includes:
- Is::Copyable, Is::Inspectable
- Defined in:
- lib/core/boundary/validator.rb
Overview
- public
Instance Method Summary collapse
-
#action(name, &block) ⇒ Object
[public].
-
#call(value, result:, reference:) ⇒ Object
[public].
-
#initialize ⇒ Validator
constructor
A new instance of Validator.
Constructor Details
#initialize ⇒ Validator
Returns a new instance of Validator.
18 19 20 |
# File 'lib/core/boundary/validator.rb', line 18 def initialize @validations = [] end |
Instance Method Details
#action(name, &block) ⇒ Object
- public
28 29 30 |
# File 'lib/core/boundary/validator.rb', line 28 def action(name, &block) @validations << {name: name, block: block} end |
#call(value, result:, reference:) ⇒ Object
- public
34 35 36 37 38 39 |
# File 'lib/core/boundary/validator.rb', line 34 def call(value, result:, reference:) @validations.each do |validation| next if validation[:block].call(value) result.errors.add(reference, validation[:name]) end end |