Module: Mongoid::Extensions::Range::ClassMethods
Relationships & Source Files | |
Defined in: | lib/mongoid/extensions/range.rb |
Instance Method Summary
-
#demongoize(object) ⇒ Range | nil
Convert the object from its mongo friendly ruby type to this type.
-
#mongoize(object) ⇒ Hash | nil
Turn the object from the ruby type we deal with to a Mongo friendly type.
- #__mongoize_hash__(object) private
- #__mongoize_range__(object) private
Instance Method Details
#__mongoize_hash__(object) (private)
[ GitHub ]# File 'lib/mongoid/extensions/range.rb', line 89
def __mongoize_hash__(object) hash = object.stringify_keys hash.slice!('min', 'max', 'exclude_end') hash.compact! hash.transform_values!(&:mongoize) hash.blank? ? nil : hash end
#__mongoize_range__(object) (private)
[ GitHub ]
#demongoize(object) ⇒ Range | nil
Convert the object from its mongo friendly ruby type to this type.
# File 'lib/mongoid/extensions/range.rb', line 54
def demongoize(object) return if object.nil? if object.is_a?(Hash) hash = object.slice('min', 'max', 'exclude_end', :min, :max, :exclude_end) unless hash.blank? begin ::Range.new(hash["min"] || hash[:min], hash["max"] || hash[:max], hash["exclude_end"] || hash[:exclude_end]) rescue ArgumentError nil end end end end
#mongoize(object) ⇒ Hash | nil
Turn the object from the ruby type we deal with to a Mongo friendly type.
# File 'lib/mongoid/extensions/range.rb', line 79
def mongoize(object) return if object.nil? case object when Hash then __mongoize_hash__(object) when Range then __mongoize_range__(object) end end