Class: Mobility::ActiveModel::BackendResetter

Inherits:
BackendResetter show all
Defined in:
lib/mobility/active_model/backend_resetter.rb

Overview

Backend resetter for ActiveModel models. Adds hook to reset backend when changes_applied or clear_changes_information methods are called on model.

Direct Known Subclasses

Mobility::ActiveRecord::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.


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

def initialize(attribute_names, &block)
  super

  model_reset_method = @model_reset_method

  %i[changes_applied clear_changes_information].each do |method|
    define_method method do
      super()
      instance_eval(&model_reset_method)
    end
  end
end