StateMachine::Integrations::Base::ClassMethods

Attributes

defaults[R]

The default options to use for state machines using this integration

Public Instance Methods

available?() click to toggle source

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.

# File lib/state_machine/integrations/base.rb, line 23
def available?
  false
end
extended(base) click to toggle source

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

# File lib/state_machine/integrations/base.rb, line 77
def extended(base)
  versions.each do |version|
     base.extend(version) if version.active?
  end
end
integration_name() click to toggle source

The name of the integration

# File lib/state_machine/integrations/base.rb, line 10
def integration_name
  @integration_name ||= begin
    name = self.name.split('::').last
    name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
    name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
    name.downcase!
    name.to_sym
  end
end
locale_path() click to toggle source

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

# File lib/state_machine/integrations/base.rb, line 70
def locale_path
  path = "#{File.dirname(__FILE__)}/#{integration_name}/locale.rb"
  path if File.exists?(path)
end
matches?(klass) click to toggle source

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

# File lib/state_machine/integrations/base.rb, line 29
def matches?(klass)
  false
end
version(name, &block) click to toggle source

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.

# File lib/state_machine/integrations/base.rb, line 62
def version(name, &block)
  versions << mod = Module.new(&block)
  mod
end
versions() click to toggle source

Tracks the various version overrides for an integration

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.