Module: Mongoid::Extensions::Set::ClassMethods

Defined in:
build/mongoid-master/lib/mongoid/extensions/set.rb

Instance Method Summary collapse

Instance Method Details

#demongoize(object) ⇒ Set

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

Examples:

Demongoize the object.

Set.demongoize([1, 2, 3])

Parameters:

  • object (Array)

    The object to demongoize.

Returns:

  • (Set)

    The set.



28
29
30
31
32
33
# File 'build/mongoid-master/lib/mongoid/extensions/set.rb', line 28

def demongoize(object)
  case object
  when ::Set then object
  when ::Array then ::Set.new(object)
  end
end

#mongoize(object) ⇒ Array | nil

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

Examples:

Mongoize the object.

Set.mongoize(Set.new([1,2,3]))

Parameters:

  • object (Set)

    The object to mongoize.

Returns:

  • (Array | nil)

    The object mongoized or nil.



44
45
46
47
48
49
50
# File 'build/mongoid-master/lib/mongoid/extensions/set.rb', line 44

def mongoize(object)
  return if object.nil?
  case object
  when ::Set then ::Array.mongoize(object.to_a).uniq
  when ::Array then ::Array.mongoize(object).uniq
  end
end