Class: Mobility::ActiveRecord::BackendResetter

Inherits:
Mobility::ActiveModel::BackendResetter show all
Defined in:
lib/mobility/active_record/backend_resetter.rb

Overview

Backend resetter for ActiveRecord models. Adds hook on reload event to Mobility::ActiveModel::BackendResetter.

Instance Method Summary collapse

Methods inherited from Mobility::ActiveModel::BackendResetter

#initialize

Methods inherited from BackendResetter

for, #initialize

Constructor Details

This class inherits a constructor from Mobility::ActiveModel::BackendResetter

Instance Method Details

#included(model_class) ⇒ Object

Parameters:

  • model_class (Class)

    Class of model to which backend resetter will be applied



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mobility/active_record/backend_resetter.rb', line 12

def included(model_class)
  model_reset_method = @model_reset_method

  model_class.class_eval do
    mod = Module.new do
      define_method :reload do
        super().tap { instance_eval &model_reset_method }
      end
    end
    include mod
  end
end