Module: Workflow

Defined in:
lib/workflow.rb,
lib/workflow/draw.rb,
lib/workflow/state.rb,
lib/workflow/event.rb,
lib/workflow/errors.rb,
lib/workflow/version.rb,
lib/workflow/specification.rb,
lib/workflow/event_collection.rb,
lib/workflow/adapters/remodel.rb,
lib/workflow/adapters/active_record.rb

Overview

See also README.markdown for documentation

Defined Under Namespace

Modules: Adapter, ClassMethods, Draw, InstanceMethods Classes: Event, EventCollection, NoTransitionAllowed, Specification, State, TransitionHalted, WorkflowDefinitionError, WorkflowError

Constant Summary

VERSION =
"1.3.0"

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/workflow.rb', line 249

def self.included(klass)
  klass.send :include, InstanceMethods

  # backup the parent workflow spec, making accessible through #inherited_workflow_spec
  if klass.superclass.respond_to?(:workflow_spec, true)
    klass.module_eval do
      # see http://stackoverflow.com/a/2495650/111995 for implementation explanation
      pro = Proc.new { klass.superclass.workflow_spec }
      singleton_class = class << self; self; end
      singleton_class.send(:define_method, :inherited_workflow_spec) do
        pro.call
      end
    end
  end

  klass.extend ClassMethods

  # Look for a hook; otherwise detect based on ancestor class.
  if klass.respond_to?(:workflow_adapter)
    klass.send :include, klass.workflow_adapter
  else
    if Object.const_defined?(:ActiveRecord) && klass < ActiveRecord::Base
      klass.send :include, Adapter::ActiveRecord
    end
    if Object.const_defined?(:Remodel) && klass < Adapter::Remodel::Entity
      klass.send :include, Adapter::Remodel::InstanceMethods
    end
  end
end