class Locomotive::Steam::Decorators::I18nDecorator

Attributes

__default_locale__[R]
__frozen_locale__[RW]
__locale__[R]
__localized_attributes__[RW]

Public Class Methods

decorate(object_or_list, locale = nil, default_locale = nil) click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 25
def decorate(object_or_list, locale = nil, default_locale = nil)
  decorated = [[object_or_list]].flatten.map do |object|
    new(object, locale, default_locale)
  end

  object_or_list.respond_to?(:localized_attributes) ? decorated.first : decorated
end
new(object, locale = nil, default_locale = nil) click to toggle source
Calls superclass method
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 12
def initialize(object, locale = nil, default_locale = nil)
  # ::Object.send(:puts, "Decorating #{object.class.name} with #{self.class.name}")

  self.__localized_attributes__ = object.localized_attributes
  self.__frozen_locale__        = false
  self.__locale__               = locale
  self.__default_locale__       = default_locale

  super(object)
end

Public Instance Methods

__default_locale__=(locale) click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 41
def __default_locale__=(locale)
  @__default_locale__ = locale.try(:to_sym)
end
__locale__=(locale) click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 35
def __locale__=(locale)
  unless self.__frozen_locale__
    @__locale__ = locale.try(:to_sym)
  end
end
__with_locale__(locale) { || ... } click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 45
def __with_locale__(locale, &block)
  old_locale, self.__locale__  = __locale__, locale.to_sym
  self.__freeze_locale__
  yield.tap do
    self.__unfreeze_locale__
    self.__locale__ = old_locale
  end