module Locomotive::Steam::Decorators

Public Instance Methods

__freeze_locale__() click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 62
def __freeze_locale__
  @__frozen_locale__ = true
end
__get_localized_value__(name) click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 74
def __get_localized_value__(name)
  field = __getobj__.public_send(name.to_sym)
  field ? field[__locale__] || field[__default_locale__] : nil
end
__is_localized_attribute__(name) click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 70
def __is_localized_attribute__(name)
  __localized_attributes__.include?(name.to_sym)
end
__set_localized_value__(name, value) click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 79
def __set_localized_value__(name, value)
  field = __getobj__.public_send(name.to_sym)
  field[__locale__] = value
end
__unfreeze_locale__() click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 66
def __unfreeze_locale__
  @__frozen_locale__ = false
end
__with_default_locale__() { || ... } click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 54
def __with_default_locale__(&block)
  if self.__default_locale__
    __with_locale__(self.__default_locale__, &block)
  else
    yield
  end
end
as_json(options = nil) click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 103
def as_json(options = nil)
  to_hash.as_json(options)
end
inspect() click to toggle source

:nocov:

# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 112
def inspect
  "[Decorated #{__getobj__.class.name}][I18n] attributes exist? " +
  __getobj__.respond_to?(:attributes).inspect +
  ', localized attributes: ' + @__localized_attributes__.inspect +
  ', locale: ' + @__locale__.inspect
end
method_missing(name, *args, &block) click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 84
def method_missing(name, *args, &block)
  if __is_localized_attribute__(name)
    __get_localized_value__(name)
  elsif name.to_s.end_with?('=') && __is_localized_attribute__(name.to_s.chop)
    __set_localized_value__(name.to_s.chop, args.first)
  else
    # Note: we want to hit the method_missing of the target object
    __getobj__.send(name, *args, &block)
  end
end
to_hash() click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 95
def to_hash
  __getobj__.to_hash.tap do |hash|
    @__localized_attributes__.keys.each do |name|
      hash[name.to_s] = __get_localized_value__(name)
    end
  end
end
to_json() click to toggle source
# File lib/locomotive/steam/decorators/i18n_decorator.rb, line 107
def to_json
  as_json.to_json
end