Class: Apipie::Validator::BooleanValidator

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

#==, #error, find, inherited, #initialize, #inspect, #inspected_fields, #merge_with, #param_name, #params_ordered, #to_json, #to_s, #valid?

Constructor Details

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

Class Method Details

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



428
429
430
431
432
# File 'lib/apipie/validator.rb', line 428

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

Instance Method Details

#descriptionObject



438
439
440
441
# File 'lib/apipie/validator.rb', line 438

def description
  string = %w(true false 1 0).map { |value| "<code>#{value}</code>" }.join(', ')
  "Must be one of: #{string}"
end

#expected_typeObject



434
435
436
# File 'lib/apipie/validator.rb', line 434

def expected_type
  'boolean'
end

#validate(value) ⇒ Object



424
425
426
# File 'lib/apipie/validator.rb', line 424

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