Module: Mongoid::Extensions::Range::ClassMethods
- Defined in:
- lib/mongoid/extensions/range.rb
Instance Method Summary collapse
-
#demongoize(object) ⇒ Range
Convert the object from its mongo friendly ruby type to this type.
-
#mongoize(object) ⇒ Hash
Turn the object from the ruby type we deal with to a Mongo friendly type.
Instance Method Details
#demongoize(object) ⇒ Range
Convert the object from its mongo friendly ruby type to this type.
55 56 57 |
# File 'lib/mongoid/extensions/range.rb', line 55 def demongoize(object) object.nil? ? nil : ::Range.new(object["min"], object["max"], object["exclude_end"]) end |
#mongoize(object) ⇒ Hash
Turn the object from the ruby type we deal with to a Mongo friendly type.
70 71 72 73 74 75 76 77 78 |
# File 'lib/mongoid/extensions/range.rb', line 70 def mongoize(object) return nil if object.nil? return object if object.is_a?(::Hash) hash = { "min" => object.first, "max" => object.last } if object.respond_to?(:exclude_end?) && object.exclude_end? hash.merge!("exclude_end" => true) end hash end |