lib/mongo_mapper/extensions/boolean.rb in mongo_mapper-0.12.0 vs lib/mongo_mapper/extensions/boolean.rb in mongo_mapper-0.13.0.beta1
- old
+ new
@@ -1,40 +1,37 @@
# encoding: UTF-8
module MongoMapper
module Extensions
module Boolean
Mapping = {
- true => true,
- 'true' => true,
- 'TRUE' => true,
- 'True' => true,
- 't' => true,
- 'T' => true,
- '1' => true,
- 1 => true,
+ 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,
+ false => false,
+ 'false' => false,
+ 'FALSE' => false,
+ 'False' => false,
+ 'f' => false,
+ 'F' => false,
+ '0' => false,
+ 0 => false,
+ 0.0 => false,
nil => nil
}
def to_mongo(value)
- if value.is_a?(Boolean)
- value
- else
- Mapping[value]
- end
+ Mapping[value]
end
def from_mongo(value)
- value.nil? ? nil : !!value
+ return nil if value == nil
+ !!value
end
end
end
end