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.


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mobility/plugins/sequel/dirty.rb', line 19

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


36
37
38
39
# File 'lib/mobility/plugins/sequel/dirty.rb', line 36

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