Module: Mobility::Backend::Sequel::Dirty::ClassMethods
- Defined in:
- lib/mobility/backend/sequel/dirty.rb
Overview
Adds hook after Mobility::Backend::Setup#setup_model to add dirty-tracking methods for translated attributes onto model class.
Instance Method Summary collapse
-
#setup_model(model_class, attributes, **options) ⇒ Object
Call setup block on a class with attributes and options.
Instance Method Details
#setup_model(model_class, attributes, **options) ⇒ Object
Call setup block on a class with attributes and options.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mobility/backend/sequel/dirty.rb', line 34 def setup_model(model_class, attributes, **) super model_class.class_eval do mod = Module.new do %w[initial_value column_change column_changed? reset_column].each do |method_name| define_method method_name do |column| if attributes.map(&:to_sym).include?(column) super("#{column}_#{Mobility.locale}".to_sym) else super(column) end end end end include mod end end |