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, #params_ordered, #to_json, #to_s, #valid?

Constructor Details

#initialize(param_description, argument) ⇒ ProcValidator

Returns a new instance of ProcValidator.



251
252
253
254
# File 'lib/apipie/validator.rb', line 251

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

Class Method Details

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



260
261
262
# File 'lib/apipie/validator.rb', line 260

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



268
269
270
# File 'lib/apipie/validator.rb', line 268

def description
  ""
end

#errorObject



264
265
266
# File 'lib/apipie/validator.rb', line 264

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

#validate(value) ⇒ Object



256
257
258
# File 'lib/apipie/validator.rb', line 256

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