Class: Mongoid::Fields::Localized
- Defined in:
- lib/mongoid/fields/localized.rb
Overview
Represents a BSON document field definition which stores different values for different user locale keys in a Ruby hashmap (BSON “Object” type). Used for internationalization (I18n) support.
Instance Attribute Summary
Attributes inherited from Standard
#default_val, #label, #name, #options
Instance Method Summary collapse
-
#demongoize(object) ⇒ Object
Demongoize the object based on the current locale.
-
#localize_present? ⇒ true | false
Is the localized field enforcing values to be present?.
-
#localized? ⇒ true | false
Is the field localized or not?.
-
#mongoize(object) ⇒ Hash
Convert the provided string into a hash for the locale.
Methods inherited from Standard
#add_atomic_changes, #association, #eval_default, #foreign_key?, #initialize, #lazy?, #object_id_field?, #pre_processed?, #type
Constructor Details
This class inherits a constructor from Mongoid::Fields::Standard
Instance Method Details
#demongoize(object) ⇒ Object
Demongoize the object based on the current locale. Will look in the hash for the current locale.
22 23 24 25 26 27 28 |
# File 'lib/mongoid/fields/localized.rb', line 22 def demongoize(object) return if object.nil? case object when Hash type.demongoize(lookup(object)) end end |
#localize_present? ⇒ true | false
Is the localized field enforcing values to be present?
46 47 48 |
# File 'lib/mongoid/fields/localized.rb', line 46 def localize_present? [:localize] == :present end |
#localized? ⇒ true | false
Is the field localized or not?
36 37 38 |
# File 'lib/mongoid/fields/localized.rb', line 36 def localized? true end |
#mongoize(object) ⇒ Hash
Convert the provided string into a hash for the locale.
58 59 60 |
# File 'lib/mongoid/fields/localized.rb', line 58 def mongoize(object) { ::I18n.locale.to_s => type.mongoize(object) } end |