123456789_123456789_123456789_123456789_123456789_

Class: Mongoid::StringifiedSymbol

Relationships & Source Files
Inherits: Object
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

Class Method Details

.demongoize(object) ⇒ Symbol

This method is for internal use only.

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:

[ GitHub ]

  
# 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 for internal use only.

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.

[ GitHub ]

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

def evolve(object)
  mongoize(object)
end

.mongoize(object) ⇒ String

This method is for internal use only.

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.

[ GitHub ]

  
# File 'lib/mongoid/stringified_symbol.rb', line 41

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