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, #format_description_value, 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



474
475
476
477
478
# File 'lib/apipie/validator.rb', line 474

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

Instance Method Details

#descriptionObject



484
485
486
487
# File 'lib/apipie/validator.rb', line 484

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

#expected_typeObject



493
494
495
# File 'lib/apipie/validator.rb', line 493

def expected_type
  'boolean'
end

#ignore_allow_blank?Boolean

Returns:

  • (Boolean)


489
490
491
# File 'lib/apipie/validator.rb', line 489

def ignore_allow_blank?
  true
end

#validate(value) ⇒ Object



470
471
472
# File 'lib/apipie/validator.rb', line 470

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