Class: Restapi::Validator::BooleanValidator

Inherits:
BaseValidator show all
Defined in:
lib/restapi/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, #initialize, #param_name, #to_json, #to_s, #valid?

Constructor Details

This class inherits a constructor from Restapi::Validator::BaseValidator

Class Method Details

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



275
276
277
278
279
# File 'lib/restapi/validator.rb', line 275

def self.build(param_description, argument, options, block)
  if argument == :bool
    self.new(param_description)
  end
end

Instance Method Details

#descriptionObject



285
286
287
# File 'lib/restapi/validator.rb', line 285

def description
  "Has to be a boolean"
end

#errorObject



281
282
283
# File 'lib/restapi/validator.rb', line 281

def error
  "Parameter #{param_name} expecting to be a boolean value, got: #{@error_value}"
end

#validate(value) ⇒ Object



271
272
273
# File 'lib/restapi/validator.rb', line 271

def validate(value)
  %w[true false].include?(value.to_s)
end