Class: Apipie::Validator::ProcValidator

Inherits:
BaseValidator show all
Defined in:
lib/apipie/validator.rb

Instance Attribute Summary

Attributes inherited from BaseValidator

#param_description

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseValidator

#expected_type, find, inherited, #merge_with, #param_name, #to_json, #to_s, #valid?

Constructor Details

#initialize(param_description, argument) ⇒ ProcValidator

Returns a new instance of ProcValidator.



155
156
157
158
# File 'lib/apipie/validator.rb', line 155

def initialize(param_description, argument)
  super(param_description)
  @proc = argument
end

Class Method Details

.build(param_description, argument, options, proc) ⇒ Object



164
165
166
# File 'lib/apipie/validator.rb', line 164

def self.build(param_description, argument, options, proc)
  self.new(param_description, argument) if argument.is_a?(Proc) && argument.arity == 1
end

Instance Method Details

#descriptionObject



172
173
174
# File 'lib/apipie/validator.rb', line 172

def description
  ""
end

#errorObject



168
169
170
# File 'lib/apipie/validator.rb', line 168

def error
  ParamInvalid.new(param_name, @error_value, @help)
end

#validate(value) ⇒ Object



160
161
162
# File 'lib/apipie/validator.rb', line 160

def validate(value)
  (@help = @proc.call(value)) === true
end