Sha256: 485aebe3a9369f0bea919c96e3a58094ca5f2fd4a497bd19d11082d818b7d6c8
Contents?: true
Size: 1.9 KB
Versions: 8
Compression:
Stored size: 1.9 KB
Contents
# encoding: utf-8 module Mongoid module Extensions module Range # Get the range as arguments for a find. # # @example Get the range as find args. # range.__find_args__ # # @return [ Array ] The range as an array. # # @since 3.0.0 def __find_args__ to_a end # Turn the object from the ruby type we deal with to a Mongo friendly # type. # # @example Mongoize the object. # range.mongoize # # @return [ Hash ] The object mongoized. # # @since 3.0.0 def mongoize ::Range.mongoize(self) end # Is this a resizable object. # # @example Is this resizable? # range.resizable? # # @return [ true ] True. # # @since 3.0.0 def resizable? true end module ClassMethods # Convert the object from it's mongo friendly ruby type to this type. # # @example Demongoize the object. # Range.demongoize({ "min" => 1, "max" => 5 }) # # @param [ Hash ] object The object to demongoize. # # @return [ Range ] The range. # # @since 3.0.0 def demongoize(object) object.nil? ? nil : ::Range.new(object["min"], object["max"]) end # Turn the object from the ruby type we deal with to a Mongo friendly # type. # # @example Mongoize the object. # Range.mongoize(1..3) # # @param [ Range ] object The object to mongoize. # # @return [ Hash ] The object mongoized. # # @since 3.0.0 def mongoize(object) object.nil? ? nil : { "min" => object.first, "max" => object.last } end end end end end ::Range.__send__(:include, Mongoid::Extensions::Range) ::Range.__send__(:extend, Mongoid::Extensions::Range::ClassMethods)
Version data entries
8 entries across 8 versions & 1 rubygems