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, #format_description_value, #ignore_allow_blank?, inherited, #inspect, #inspected_fields, #merge_with, #param_name, #params_ordered, raise_if_missing_params, #to_json, #to_s, #valid?

Constructor Details

#initialize(param_description, argument) ⇒ ProcValidator

Returns a new instance of ProcValidator.



303
304
305
306
# File 'lib/apipie/validator.rb', line 303

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

Class Method Details

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



312
313
314
# File 'lib/apipie/validator.rb', line 312

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



320
321
322
# File 'lib/apipie/validator.rb', line 320

def description
  ""
end

#errorObject



316
317
318
# File 'lib/apipie/validator.rb', line 316

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

#validate(value) ⇒ Object



308
309
310
# File 'lib/apipie/validator.rb', line 308

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