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/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, NoTransitionAllowed, Specification, State, TransitionHalted, WorkflowDefinitionError, WorkflowError

Constant Summary

VERSION =
"1.2.0"

Class Method Summary (collapse)

Class Method Details

+ (Object) included(klass)



248
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
# File 'lib/workflow.rb', line 248

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

  if Object.const_defined?(:ActiveRecord)
    if klass < ActiveRecord::Base
      klass.send :include, Adapter::ActiveRecord::InstanceMethods
      klass.send :extend, Adapter::ActiveRecord::Scopes
      klass.before_validation :write_initial_state
    end
  elsif Object.const_defined?(:Remodel)
    if klass < Adapter::Remodel::Entity
      klass.send :include, Remodel::InstanceMethods
    end
  end
end