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

Constructor Details

#initialize(param_description, argument) ⇒ ProcValidator

Returns a new instance of ProcValidator.



293
294
295
296
# File 'lib/apipie/validator.rb', line 293

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

Class Method Details

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



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

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



310
311
312
# File 'lib/apipie/validator.rb', line 310

def description
  ""
end

#errorObject



306
307
308
# File 'lib/apipie/validator.rb', line 306

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

#validate(value) ⇒ Object



298
299
300
# File 'lib/apipie/validator.rb', line 298

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