Class: Mongoid::StringifiedSymbol

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/stringified_symbol.rb

Overview

A class which sends values to the database as Strings but returns them to the user as Symbols.

Class Method Summary collapse

Class Method Details

.demongoize(object) ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Examples:

Demongoize the object.

Mongoid::StringifiedSymbol.demongoize('hedgehog')

Parameters:

  • object (Object)

    The object to demongoize.

Returns:

  • (Symbol)

    The object.



22
23
24
25
26
27
28
# File 'lib/mongoid/stringified_symbol.rb', line 22

def demongoize(object)
  if object.nil?
    object
  else
    object.to_s.to_sym
  end
end

.evolve(object) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Turn the object from the Ruby type into the type type used in MQL queries.

Examples:

Evolve the object.

Mongoid::StringifiedSymbol.evolve(:hedgehog)

Parameters:

  • object (Object)

    The object to evolve.

Returns:

  • (String)

    The object evolved.



60
61
62
# File 'lib/mongoid/stringified_symbol.rb', line 60

def evolve(object)
  mongoize(object)
end

.mongoize(object) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Turn the object from the Ruby type into the type type used for MongoDB persistence.

Examples:

Mongoize the object.

Mongoid::StringifiedSymbol.mongoize(:hedgehog)

Parameters:

  • object (Object)

    The object to mongoize.

Returns:

  • (String)

    The object mongoized.



41
42
43
44
45
46
47
# File 'lib/mongoid/stringified_symbol.rb', line 41

def mongoize(object)
   if object.nil?
     object
   else
     object.to_s
   end
end