Module StateMachine::Integrations::Base::ClassMethods
In: lib/state_machine/integrations/base.rb

Methods

Attributes

defaults  [R]  The default options to use for state machines using this integration

Public Instance methods

Whether this integration is available for the current library. This is usually only true if the ORM that the integration is for is currently defined. Default is false.

[Source]

    # File lib/state_machine/integrations/base.rb, line 23
23:         def available?
24:           false
25:         end

Extends the given object with any version overrides that are currently active

[Source]

    # File lib/state_machine/integrations/base.rb, line 77
77:         def extended(base)
78:           versions.each do |version|
79:              base.extend(version) if version.active?
80:           end
81:         end

The name of the integration

[Source]

    # File lib/state_machine/integrations/base.rb, line 10
10:         def integration_name
11:           @integration_name ||= begin
12:             name = self.name.split('::').last
13:             name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
14:             name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
15:             name.downcase!
16:             name.to_sym
17:           end
18:         end

The path to the locale file containing translations for this integration. This file will only exist for integrations that actually support i18n.

[Source]

    # File lib/state_machine/integrations/base.rb, line 70
70:         def locale_path
71:           path = "#{File.dirname(__FILE__)}/#{integration_name}/locale.rb"
72:           path if File.exists?(path)
73:         end

Whether the integration should be used for the given class. Default is false.

[Source]

    # File lib/state_machine/integrations/base.rb, line 29
29:         def matches?(klass)
30:           false
31:         end

Creates a new version override for an integration. When this integration is activated, each version that is marked as active will also extend the integration.

Example

  module StateMachine
    module Integrations
      module ORMLibrary
        version '0.2.x - 0.3.x' do
          def self.active?
            ::ORMLibrary::VERSION >= '0.2.0' && ::ORMLibrary::VERSION < '0.4.0'
          end

          def invalidate(object, attribute, message, values = [])
            # Override here...
          end
        end
      end
    end
  end

In the above example, a version override is defined for the ORMLibrary integration when the version is between 0.2.x and 0.3.x.

[Source]

    # File lib/state_machine/integrations/base.rb, line 62
62:         def version(name, &block)
63:           versions << mod = Module.new(&block)
64:           mod
65:         end

Tracks the various version overrides for an integration

[Source]

    # File lib/state_machine/integrations/base.rb, line 34
34:         def versions
35:           @versions ||= []
36:         end

[Validate]