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 BackendResetter

for

Constructor Details

#initialize(attribute_names) { ... } ⇒ BackendResetter

Returns a new instance of BackendResetter.

Parameters:

  • attribute_names (Array<String>)

    Names of attributes whose backends should be reset

Yields:

  • Backend to reset as context for block

Raises:

  • (ArgumentError)

    if no block is provided.


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

def initialize(attribute_names, &block)
  super

  model_reset_method = @model_reset_method

  define_method :reload do |*args|
    super(*args).tap { instance_eval(&model_reset_method) }
  end
end