Sha256: a795dad597509f50c32b7921bd6526107d3fe1950566bf70736d1633ec9f9df1

Contents?: true

Size: 1.5 KB

Versions: 14

Compression:

Stored size: 1.5 KB

Contents

module StateMachine
  module Integrations #:nodoc:
    module ActiveModel
      # Represents the encapsulation of all of the details to be included in an
      # update to state machine observers.  This allows multiple arguments to
      # get passed to an observer method (instead of just a single +object+)
      # while still respecting the way in which ActiveModel checks for the
      # object's list of observers.
      class ObserverUpdate
        # The method to invoke on the observer
        attr_reader :method
        
        # The object being transitioned
        attr_reader :object
        
        # The transition being run
        attr_reader :transition
        
        def initialize(method, object, transition) #:nodoc:
          @method, @object, @transition = method, object, transition
        end
        
        # The arguments to pass into the method
        def args
          [object, transition]
        end
        
        # The class of the object being transitioned.  Normally the object
        # getting passed into observer methods is the actual instance of the
        # ActiveModel class.  ActiveModel uses that instance's class to check
        # for enabled / disabled observers.
        # 
        # Since state_machine is passing an ObserverUpdate instance into observer
        # methods, +class+ needs to be overridden so that ActiveModel can still
        # get access to the enabled / disabled observers.
        def class
          object.class
        end
      end
    end
  end
end

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_update.rb
telvue_state_machine-1.2.3 lib/state_machine/integrations/active_model/observer_update.rb
telvue_state_machine-1.2.2 lib/state_machine/integrations/active_model/observer_update.rb
state_machine_deuxito-0.0.1 lib/state_machine/integrations/active_model/observer_update.rb
telvue_state_machine-1.2.1 lib/state_machine/integrations/active_model/observer_update.rb
cm-state_machine-1.2.0.1 lib/state_machine/integrations/active_model/observer_update.rb
spree-state_machine-2.0.0.beta4 lib/state_machine/integrations/active_model/observer_update.rb
spree-state_machine-2.0.0.beta3 lib/state_machine/integrations/active_model/observer_update.rb
spree-state_machine-2.0.0.beta2 lib/state_machine/integrations/active_model/observer_update.rb
spree-state_machine-2.0.0.beta1 lib/state_machine/integrations/active_model/observer_update.rb
culturecode-state_machine-1.2.1 lib/state_machine/integrations/active_model/observer_update.rb
automat-1.2.0 lib/state_machine/integrations/active_model/observer_update.rb
glebtv_state_machine-1.3.0 lib/state_machine/integrations/active_model/observer_update.rb
state_machine-1.2.0 lib/state_machine/integrations/active_model/observer_update.rb