Module: MongoMapper::Extensions::Boolean

Included in:
Boolean
Defined in:
lib/mongo_mapper/extensions/boolean.rb

Constant Summary collapse

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     => nil
}

Instance Method Summary collapse

Instance Method Details

#from_mongo(value) ⇒ Object



35
36
37
# File 'lib/mongo_mapper/extensions/boolean.rb', line 35

def from_mongo(value)
  value.nil? ? nil : !!value
end

#to_mongo(value) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/mongo_mapper/extensions/boolean.rb', line 27

def to_mongo(value)
  if value.is_a?(Boolean)
    value
  else
    Mapping[value]
  end
end