Module: Workflow

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

Overview

See also README.markdown for documentation

Defined Under Namespace

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

Constant Summary collapse

VERSION =
"1.3.1"

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/workflow.rb', line 278

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