Class: Cfer::Auster::ParamValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/cfer/auster/param_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(&validator) ⇒ ParamValidator

Returns a new instance of ParamValidator.



6
7
8
9
10
11
# File 'lib/cfer/auster/param_validator.rb', line 6

def initialize(&validator)
  raise "validator must be a Proc." unless validator.is_a?(Proc)
  raise "validator must be arity 2." unless validator.arity == 2

  @validator = validator
end

Instance Method Details

#validate(parameters) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/cfer/auster/param_validator.rb', line 13

def validate(parameters)
  raise "parameters must be a Hash." unless parameters.is_a?(Hash)

  errors = []
  @validator.call(parameters, errors)
  errors
end