Module: Mongoid::Extensions::Range::ClassMethods
- Defined in:
- build/mongoid-8.1/lib/mongoid/extensions/range.rb
Instance Method Summary collapse
-
#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.
Instance Method Details
#demongoize(object) ⇒ Range | nil
Note:
Ruby 2.6 and lower do not support endless ranges that Ruby 2.7+ support.
Convert the object from its mongo friendly ruby type to this type.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'build/mongoid-8.1/lib/mongoid/extensions/range.rb', line 50 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 # can be removed when Ruby version >= 2.7 nil end end end end |
#mongoize(object) ⇒ Hash | nil
Turn the object from the ruby type we deal with to a Mongo friendly type.
75 76 77 78 79 80 81 |
# File 'build/mongoid-8.1/lib/mongoid/extensions/range.rb', line 75 def mongoize(object) return if object.nil? case object when Hash then __mongoize_hash__(object) when Range then __mongoize_range__(object) end end |