Class: Mobility::Plugins::Sequel::Dirty::MethodsBuilder

Inherits:
Module
  • Object
show all
Defined in:
lib/mobility/plugins/sequel/dirty.rb

Overview

Builds module which overrides dirty methods to handle translated as well as normal (untranslated) attributes.

Instance Method Summary collapse

Constructor Details

#initialize(*attribute_names) ⇒ MethodsBuilder

Returns a new instance of MethodsBuilder.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mobility/plugins/sequel/dirty.rb', line 34

def initialize(*attribute_names)
  # Although we load the plugin in the included callback method, we
  # need to include this module here in advance to ensure that its
  # instance methods are included *before* the ones defined here.
  include ::Sequel::Plugins::Dirty::InstanceMethods

  %w[initial_value column_change column_changed? reset_column].each do |method_name|
    define_method method_name do |column|
      if attribute_names.map(&:to_sym).include?(column)
        super(Mobility.normalize_locale_accessor(column).to_sym)
      else
        super(column)
      end
    end
  end
end

Instance Method Details

#included(model_class) ⇒ Object



51
52
53
54
# File 'lib/mobility/plugins/sequel/dirty.rb', line 51

def included(model_class)
  # this just adds Sequel::Plugins::Dirty to @plugins
  model_class.plugin :dirty
end