Class: Core::Boundary::Validator

Inherits:
Object
  • Object
show all
Includes:
Inspect
Defined in:
lib/core/boundary/validator.rb

Overview

public

Instance Method Summary collapse

Constructor Details

#initializeValidator

Returns a new instance of Validator.



15
16
17
# File 'lib/core/boundary/validator.rb', line 15

def initialize
  @validations = []
end

Instance Method Details

#action(name, &block) ⇒ Object

public


27
28
29
# File 'lib/core/boundary/validator.rb', line 27

def action(name, &block)
  @validations << {name: name, block: block}
end

#call(value, result:, reference:) ⇒ Object

public


33
34
35
36
37
38
# File 'lib/core/boundary/validator.rb', line 33

def call(value, result:, reference:)
  @validations.each do |validation|
    next if validation[:block].call(value)
    result.errors.add(reference, validation[:name])
  end
end

#initialize_copyObject



19
20
21
22
23
# File 'lib/core/boundary/validator.rb', line 19

def initialize_copy(...)
  @validations = @validations.copy

  super
end