Class: Mobility::Sequel::ColumnChanges
- Inherits:
-
Module
- Object
- Module
- Mobility::Sequel::ColumnChanges
- Defined in:
- lib/mobility/sequel/column_changes.rb
Overview
Internal class used to force Sequel model to notice changes when mobility setter method is called.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ ColumnChanges
constructor
A new instance of ColumnChanges.
Constructor Details
#initialize(attributes) ⇒ ColumnChanges
Returns a new instance of ColumnChanges.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mobility/sequel/column_changes.rb', line 11 def initialize(attributes) @attributes = attributes attributes.each do |attribute| define_method "#{attribute}=".freeze do |value, **| if ![:super] && send(attribute) != value locale = [:locale] || Mobility.locale column = attribute.to_sym column_with_locale = :"#{attribute}_#{Mobility.normalize_locale(locale)}" @changed_columns << column_with_locale if !changed_columns.include?(column_with_locale) @changed_columns << column if !changed_columns.include?(column) end super(value, **) end end end |