Module: Workflow::ClassMethods

Defined in:
lib/workflow.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#workflow_specObject (readonly)

Returns the value of attribute workflow_spec.



190
191
192
# File 'lib/workflow.rb', line 190

def workflow_spec
  @workflow_spec
end

Instance Method Details

#workflow { ... } ⇒ nil

Define workflow for the class.

Workflow definition takes place inside the yielded block.


class Article
  include Workflow
  workflow do
    state :new do
      event :submit, :transitions_to => :awaiting_review
    end
    state :awaiting_review do
      event :review, :transitions_to => :being_reviewed
    end
    state :being_reviewed do
      event :accept, :transitions_to => :accepted
      event :reject, :transitions_to => :rejected
    end
    state :accepted
    state :rejected
  end
end

Yields:

  • [] Specification of workflow. Example below and in README.markdown

Returns:

  • (nil)

See Also:

  • Specification::state
  • Specification::event


239
240
241
# File 'lib/workflow.rb', line 239

def workflow(&specification)
  assign_workflow Specification.new(Hash.new, &specification)
end

#workflow_column(column_name = nil) ⇒ void

This method returns an undefined value.

Instructs Workflow which column to use to persist workflow state.

Parameters:

  • optional (Symbol)

    column_name name of column on table



196
197
198
199
200
201
202
203
204
# File 'lib/workflow.rb', line 196

def workflow_column(column_name=nil)
  if column_name
    @workflow_state_column_name = column_name.to_sym
  end
  if !instance_variable_defined?('@workflow_state_column_name') && superclass.respond_to?(:workflow_column)
    @workflow_state_column_name = superclass.workflow_column
  end
  @workflow_state_column_name ||= :workflow_state
end