Class: ContainerConfig::Coercer::Boolean

Inherits:
Base
  • Object
show all
Defined in:
lib/container_config/coercer/boolean.rb

Overview

Boolean type coercer

Instance Method Summary collapse

Instance Method Details

#coerce(value) ⇒ Boolean

Coerces the given value into a boolean

Parameters:

  • value (Object)

    given value

Returns:



26
27
28
29
30
31
# File 'lib/container_config/coercer/boolean.rb', line 26

def coerce(value)
  # If a digit is passed, check if it is non-zero and return true for non-zero values
  return value.to_i != 0 if value.respond_to?(:to_i) && value.to_i.to_s == value.to_s

  value.to_s.casecmp?("true")
end

#nameObject



10
11
12
# File 'lib/container_config/coercer/boolean.rb', line 10

def name
  "Boolean"
end

#typeObject



15
16
17
# File 'lib/container_config/coercer/boolean.rb', line 15

def type
  :boolean
end