Class: Boolean

Inherits:
Object show all
Defined in:
lib/mongo_mapper/support.rb

Constant Summary collapse

BOOLEAN_MAPPING =
{
  true => true, 'true' => true, 'TRUE' => true, 'True' => true, 't' => true, 'T' => true, '1' => true, 1 => true, 1.0 => true,
  false => false, 'false' => false, 'FALSE' => false, 'False' => false, 'f' => false, 'F' => false, '0' => false, 0 => false, 0.0 => false, nil => false
}

Class Method Summary collapse

Class Method Details

.from_mongo(value) ⇒ Object



43
44
45
# File 'lib/mongo_mapper/support.rb', line 43

def self.from_mongo(value)
  !!value
end

.to_mongo(value) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/mongo_mapper/support.rb', line 33

def self.to_mongo(value)
  if value.is_a?(Boolean)
    value
  else
    v = BOOLEAN_MAPPING[value]
    v = value.to_s.downcase == 'true' if v.nil? # Check all mixed case spellings for true
    v
  end
end