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(attributes) { ... } ⇒ BackendResetter

Returns a new instance of BackendResetter.

Parameters:

  • attributes (Array<String>)

    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(attributes)
  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