Module: Mobility::Plugins::ActiveModel::Dirty::BackendMethods

Defined in:
lib/mobility/plugins/active_model/dirty.rb

Backend Accessors collapse

Instance Method Details

#write(locale, value, **options) ⇒ Object

Updates translation for provided locale without calling backend’s methods to persist the changes.

Parameters:

  • locale (Symbol)

    Locale to write

  • value (Object)

    Value to write

  • options (Hash)

Returns:

  • (Object)

    Updated value



355
356
357
358
359
360
361
362
363
# File 'lib/mobility/plugins/active_model/dirty.rb', line 355

def write(locale, value, **options)
  locale_accessor = Mobility.normalize_locale_accessor(attribute, locale)
  if model.changed_attributes.has_key?(locale_accessor) && model.changed_attributes[locale_accessor] == value
    mutations_from_mobility.restore_attribute!(locale_accessor)
  elsif read(locale, **options.merge(locale: true)) != value
    mutations_from_mobility.attribute_will_change!(locale_accessor)
  end
  super
end