Module: Mongoid::Globalize

Extended by:
ActiveSupport::Concern
Defined in:
lib/mongoid_globalize/attributes.rb,
lib/mongoid_globalize/document_translation.rb,
lib/mongoid_globalize/instance_methods.rb,
lib/mongoid_globalize/fields_builder.rb,
lib/mongoid_globalize/class_methods.rb,
lib/mongoid_globalize/act_macro.rb,
lib/mongoid_globalize/adapter.rb,
lib/mongoid_globalize.rb

Overview

Helper class for storing values per locale. Used by Mongoid::Globalize::Adapter to stash and cache attribute values.

Defined Under Namespace

Modules: ActMacro, ClassMethods, InstanceMethods Classes: Adapter, Attributes, DocumentTranslation, FieldsBuilder

Class Method Summary collapse

Class Method Details

.fallbacks(locale = self.locale) ⇒ Object



48
49
50
# File 'lib/mongoid_globalize.rb', line 48

def fallbacks(locale = self.locale)
  fallbacks? ? I18n.fallbacks[locale] : [locale.to_sym]
end

.fallbacks?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/mongoid_globalize.rb', line 44

def fallbacks?
  I18n.respond_to?(:fallbacks)
end

.localeObject



22
23
24
# File 'lib/mongoid_globalize.rb', line 22

def locale
  read_locale || I18n.locale
end

.locale=(locale) ⇒ Object



26
27
28
# File 'lib/mongoid_globalize.rb', line 26

def locale=(locale)
  set_locale(locale)
end

.with_locale(locale, &block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/mongoid_globalize.rb', line 30

def with_locale(locale, &block)
  previous_locale = read_locale
  set_locale(locale)
  result = yield(locale)
  set_locale(previous_locale)
  result
end

.with_locales(*locales, &block) ⇒ Object



38
39
40
41
42
# File 'lib/mongoid_globalize.rb', line 38

def with_locales(*locales, &block)
  locales.flatten.map do |locale|
    with_locale(locale, &block)
  end
end