class Para::I18n::AttributeTranslation::Attachment
Public Class Methods
matches?(model, attribute)
click to toggle source
# File lib/para/i18n/attribute_translation/attachment.rb, line 19 def self.matches?(model, attribute) model.reflections.key?("#{attribute}_attachment") && model.reflections.key?("#{attribute}_blob") end
prepare(model, attribute)
click to toggle source
# File lib/para/i18n/attribute_translation/attachment.rb, line 24 def self.prepare(model, attribute) return unless matches?(model, attribute) (I18n.available_locales - [I18n.default_locale]).each do |locale| new(locale, model, attribute).prepare_translated_attachment end end
Public Instance Methods
prepare_translated_attachment()
click to toggle source
# File lib/para/i18n/attribute_translation/attachment.rb, line 32 def prepare_translated_attachment model.alias_method(untranslated_getter_name, attribute) model.alias_method(untranslated_setter_name, :"#{attribute}=") model.has_one_attached(reflection_name) end
read(resource)
click to toggle source
# File lib/para/i18n/attribute_translation/attachment.rb, line 5 def read(resource) attachment = resource.public_send(reflection_name) if default_locale? || attachment.attached? || !fallback_locale attachment elsif fallback_locale self.class.new(fallback_locale, model, attribute).read(resource) end end
write(resource, value)
click to toggle source
# File lib/para/i18n/attribute_translation/attachment.rb, line 15 def write(resource, value) resource.public_send(:"#{reflection_name}=", value) end
Private Instance Methods
reflection_name()
click to toggle source
# File lib/para/i18n/attribute_translation/attachment.rb, line 40 def reflection_name @reflection_name ||= if default_locale? untranslated_getter_name else [attribute, locale, "translation"].join("_") end end
untranslated_getter_name()
click to toggle source
# File lib/para/i18n/attribute_translation/attachment.rb, line 48 def untranslated_getter_name @untranslated_getter_name ||= :"untranslated_#{attribute}" end
untranslated_setter_name()
click to toggle source
# File lib/para/i18n/attribute_translation/attachment.rb, line 52 def untranslated_setter_name @untranslated_setter_name ||= :"untranslated_#{attribute}=" end