Module: Mobility::Plugins::Sequel::Dirty::BackendMethods

Defined in:
lib/mobility/plugins/sequel/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) (defaults to: {})

Returns:

  • (Object)

    Updated value


46
47
48
49
50
51
52
53
54
55
# File 'lib/mobility/plugins/sequel/dirty.rb', line 46

def write(locale, value, options = {})
  locale_accessor = Mobility.normalize_locale_accessor(attribute, locale).to_sym
  if model.column_changes.has_key?(locale_accessor) && model.initial_values[locale_accessor] == value
    super
    [model.changed_columns, model.initial_values].each { |h| h.delete(locale_accessor) }
  elsif read(locale, options.merge(fallback: false)) != value
    model.will_change_column(locale_accessor)
    super
  end
end