Sha256: 93366bd2a4504da2fd4ee6eb5b5abdec68b7fb6521464e07c45ece4f6fa0f621

Contents?: true

Size: 1.08 KB

Versions: 14

Compression:

Stored size: 1.08 KB

Contents

module StateMachine
  module Integrations #:nodoc:
    module ActiveModel
      # Adds support for invoking callbacks on ActiveModel observers with more
      # than one argument (e.g. the record *and* the state transition).  By
      # default, ActiveModel only supports passing the record into the
      # callbacks.
      # 
      # For example:
      # 
      #   class VehicleObserver < ActiveModel::Observer
      #     # The default behavior: only pass in the record
      #     def after_save(vehicle)
      #     end
      #     
      #     # Custom behavior: allow the transition to be passed in as well
      #     def after_transition(vehicle, transition)
      #       Audit.log(vehicle, transition)
      #     end
      #   end
      module Observer
        def update_with_transition(observer_update)
          method = observer_update.method
          send(method, *observer_update.args) if respond_to?(method)
        end
      end
    end
  end
end

ActiveModel::Observer.class_eval do
  include StateMachine::Integrations::ActiveModel::Observer
end if defined?(ActiveModel::Observer)

Version data entries

14 entries across 14 versions & 9 rubygems

Version Path
state_machine_updated_for_ruby_3_2-2.0.0 lib/state_machine/integrations/active_model/observer.rb
telvue_state_machine-1.2.3 lib/state_machine/integrations/active_model/observer.rb
telvue_state_machine-1.2.2 lib/state_machine/integrations/active_model/observer.rb
state_machine_deuxito-0.0.1 lib/state_machine/integrations/active_model/observer.rb
telvue_state_machine-1.2.1 lib/state_machine/integrations/active_model/observer.rb
cm-state_machine-1.2.0.1 lib/state_machine/integrations/active_model/observer.rb
spree-state_machine-2.0.0.beta4 lib/state_machine/integrations/active_model/observer.rb
spree-state_machine-2.0.0.beta3 lib/state_machine/integrations/active_model/observer.rb
spree-state_machine-2.0.0.beta2 lib/state_machine/integrations/active_model/observer.rb
spree-state_machine-2.0.0.beta1 lib/state_machine/integrations/active_model/observer.rb
culturecode-state_machine-1.2.1 lib/state_machine/integrations/active_model/observer.rb
automat-1.2.0 lib/state_machine/integrations/active_model/observer.rb
glebtv_state_machine-1.3.0 lib/state_machine/integrations/active_model/observer.rb
state_machine-1.2.0 lib/state_machine/integrations/active_model/observer.rb