Module: Mobility::Backend::Sequel::Dirty

Defined in:
lib/mobility/backend/sequel/dirty.rb

Overview

Dirty tracking for Sequel models which use the Sequel::Plugins::Dirty plugin.

Defined Under Namespace

Modules: ClassMethods

Backend Accessors collapse

Class Method Summary collapse

Class Method Details

.included(backend_class) ⇒ Object

Parameters:

  • backend_class (Class)

    Class of backend



26
27
28
# File 'lib/mobility/backend/sequel/dirty.rb', line 26

def self.included(backend_class)
  backend_class.extend(ClassMethods)
end

Instance Method Details

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

Returns Updated value.

Parameters:

  • locale (Symbol)

    Locale to write

  • value (Object)

    Value to write

  • options (Hash)

Returns:



13
14
15
16
17
18
19
20
21
22
# File 'lib/mobility/backend/sequel/dirty.rb', line 13

def write(locale, value, **options)
  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) }
  else
    model.will_change_column("#{attribute}_#{locale}".to_sym)
    super
  end
end