Sha256: 0b525b20a692563078a08bdbab0470be742925b453f896a18de30a5c611f90ad

Contents?: true

Size: 977 Bytes

Versions: 29

Compression:

Stored size: 977 Bytes

Contents

module StateMachine
  module Integrations #:nodoc:
    module ActiveModel
      version '2.x' do
        def self.active?
          !defined?(::ActiveModel::VERSION) || ::ActiveModel::VERSION::MAJOR == 2
        end
        
        def define_validation_hook
          define_helper :instance, <<-end_eval, __FILE__, __LINE__ + 1
            def valid?(*)
              self.class.state_machines.transitions(self, #{action.inspect}, :after => false).perform { super }
            end
          end_eval
        end
      end
      
      version '3.0.x' do
        def self.active?
          defined?(::ActiveModel::VERSION) && ::ActiveModel::VERSION::MAJOR == 3 && ::ActiveModel::VERSION::MINOR == 0
        end
        
        def define_validation_hook
          # +around+ callbacks don't have direct access to results until AS 3.1
          owner_class.set_callback(:validation, :after, 'value', :prepend => true)
          super
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 10 rubygems

Version Path
state_machine_updated_for_ruby_3_2-2.0.0 lib/state_machine/integrations/active_model/versions.rb
telvue_state_machine-1.2.3 lib/state_machine/integrations/active_model/versions.rb
telvue_state_machine-1.2.2 lib/state_machine/integrations/active_model/versions.rb
state_machine_deuxito-0.0.1 lib/state_machine/integrations/active_model/versions.rb
telvue_state_machine-1.2.1 lib/state_machine/integrations/active_model/versions.rb
cm-state_machine-1.2.0.1 lib/state_machine/integrations/active_model/versions.rb
spree-state_machine-2.0.0.beta4 lib/state_machine/integrations/active_model/versions.rb
spree-state_machine-2.0.0.beta3 lib/state_machine/integrations/active_model/versions.rb
spree-state_machine-2.0.0.beta2 lib/state_machine/integrations/active_model/versions.rb
spree-state_machine-2.0.0.beta1 lib/state_machine/integrations/active_model/versions.rb
culturecode-state_machine-1.2.1 lib/state_machine/integrations/active_model/versions.rb
automat-1.2.0 lib/state_machine/integrations/active_model/versions.rb
glebtv_state_machine-1.3.0 lib/state_machine/integrations/active_model/versions.rb
state_machine-1.2.0 lib/state_machine/integrations/active_model/versions.rb
state_machine-1.1.2 lib/state_machine/integrations/active_model/versions.rb
state_machine-1.1.1 lib/state_machine/integrations/active_model/versions.rb
state_machine-1.1.0 lib/state_machine/integrations/active_model/versions.rb
state_machine-1.0.3 lib/state_machine/integrations/active_model/versions.rb
hsume2-state_machine-1.0.5 lib/state_machine/integrations/active_model/versions.rb
state_machine-1.0.2 lib/state_machine/integrations/active_model/versions.rb