Class: Mongoid::Fields::Localized

Inherits:
Standard
  • Object
show all
Defined in:
lib/mongoid/fields/localized.rb

Instance Attribute Summary

Attributes inherited from Standard

#default_val, #label, #name, #options

Instance Method Summary collapse

Methods inherited from Standard

#add_atomic_changes, #constraint, #eval_default, #foreign_key?, #initialize, #lazy?, #metadata, #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.

Examples:

Get the demongoized value.

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

Since:

  • 2.3.0



17
18
19
20
21
# File 'lib/mongoid/fields/localized.rb', line 17

def demongoize(object)
  if object
    type.demongoize(lookup(object))
  end
end

#localized?true, false

Is the field localized or not?

Examples:

Is the field localized?

field.localized?

Since:

  • 2.3.0



31
32
33
# File 'lib/mongoid/fields/localized.rb', line 31

def localized?
  true
end

#mongoize(object) ⇒ Hash

Convert the provided string into a hash for the locale.

Examples:

Serialize the value.

field.mongoize("testing")

Since:

  • 2.3.0



45
46
47
# File 'lib/mongoid/fields/localized.rb', line 45

def mongoize(object)
  { ::I18n.locale.to_s => type.mongoize(object) }
end