Sha256: 262d54ab32bc614dc0a19d705c308fbe88f5092a0cfc8a390b3d2cda8005b8fb
Contents?: true
Size: 1.9 KB
Versions: 24
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 its 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
24 entries across 24 versions & 3 rubygems