Parent

Class/Module Index [+]

Quicksearch

Mongoid::Fields::Serializable::Localized

Defines the behaviour for localized string fields.

Public Instance Methods

deserialize(object) click to toggle source

Deserialize the object based on the current locale. Will look in the hash for the current locale.

@example Get the deserialized value.

field.deserialize({ "en" => "testing" })

@param [ Hash ] object The hash of translations.

@return [ String ] The value for the current locale.

@since 2.3.0

# File lib/mongoid/fields/serializable/localized.rb, line 20
def deserialize(object)
  object[::I18n.locale.to_s]
end
serialize(object) click to toggle source

Convert the provided string into a hash for the locale.

@example Serialize the value.

field.serialize("testing")

@param [ String ] object The string to convert.

@return [ Hash ] The locale with string translation.

@since 2.3.0

# File lib/mongoid/fields/serializable/localized.rb, line 34
def serialize(object)
  { ::I18n.locale.to_s => object.try(:to_s) }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.