Class: Mongoid::Fields::Serializable::Localized
- Includes:
- Mongoid::Fields::Serializable
- Defined in:
- lib/mongoid/fields/serializable/localized.rb
Overview
Defines the behaviour for localized string fields.
Instance Attribute Summary
Attributes included from Mongoid::Fields::Serializable
#default_val, #label, #localize, #name, #options
Instance Method Summary collapse
-
#deserialize(object) ⇒ String
Deserialize the object based on the current locale.
-
#serialize(object) ⇒ Hash
Convert the provided string into a hash for the locale.
Methods included from Mongoid::Fields::Serializable
#constraint, #eval_default, #localized?, #metadata, #object_id_field?, #type, #versioned?
Instance Method Details
#deserialize(object) ⇒ String
Deserialize the object based on the current locale. Will look in the hash for the current locale.
21 22 23 |
# File 'lib/mongoid/fields/serializable/localized.rb', line 21 def deserialize(object) object[::I18n.locale.to_s] end |
#serialize(object) ⇒ Hash
Convert the provided string into a hash for the locale.
35 36 37 |
# File 'lib/mongoid/fields/serializable/localized.rb', line 35 def serialize(object) { ::I18n.locale.to_s => object.try(:to_s) } end |