Class: Configurable::ConfigTypes::BooleanType

Inherits:
ObjectType
  • Object
show all
Defined in:
lib/configurable/config_types/boolean_type.rb

Instance Method Summary collapse

Methods inherited from ObjectType

cast, errors, inherited, #initialize, matches, matches?, subclass, uncast, #uncast

Constructor Details

This class inherits a constructor from Configurable::ConfigTypes::ObjectType

Instance Method Details

#cast(input) ⇒ Object

Casts the input to a boolean ie:

true, 'true'   => true
false, 'false  => false

All other inputs raise an ArgumentError.



12
13
14
15
16
17
18
19
# File 'lib/configurable/config_types/boolean_type.rb', line 12

def cast(input)
  case input
  when true, false then input
  when 'true'      then true
  when 'false'     then false
  else raise ArgumentError, "invalid value for boolean: #{input.inspect}"
  end
end