Module: Mongoid::Extensions::Range::ClassMethods

Defined in:
lib/mongoid/extensions/range.rb

Instance Method Summary collapse

Instance Method Details

#demongoize(object) ⇒ Range

Convert the object from its mongo friendly ruby type to this type.

Examples:

Demongoize the object.

Range.demongoize({ "min" => 1, "max" => 5 })

Parameters:

  • object (Hash)

    The object to demongoize.

Returns:

Since:

  • 3.0.0



55
56
57
# File 'lib/mongoid/extensions/range.rb', line 55

def demongoize(object)
  object.nil? ? nil : ::Range.new(object["min"], object["max"])
end

#mongoize(object) ⇒ Hash

Turn the object from the ruby type we deal with to a Mongo friendly type.

Examples:

Mongoize the object.

Range.mongoize(1..3)

Parameters:

  • object (Range)

    The object to mongoize.

Returns:

  • (Hash)

    The object mongoized.

Since:

  • 3.0.0



70
71
72
# File 'lib/mongoid/extensions/range.rb', line 70

def mongoize(object)
  object.nil? ? nil : { "min" => object.first, "max" => object.last }
end