Module: Workflow::Definition

Extended by:
ActiveSupport::Concern
Included in:
Workflow
Defined in:
lib/workflow/definition.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#current_stateState

Returns a state object representing the current workflow state.

Returns:

  • (State)

    Current workflow state



9
10
11
12
13
# File 'lib/workflow/definition.rb', line 9

def current_state
  loaded_state = load_workflow_state
  res = workflow_spec.states.find { |t| t.name == loaded_state.to_sym } if loaded_state
  res || workflow_spec.initial_state
end

#workflow_specSpecification

The specification for this object. Could be set on a singleton for the object, on the object's class, Or else on a superclass of the object.

Returns:

  • (Specification)

    The Specification that applies to this object.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/workflow/definition.rb', line 19

def workflow_spec
  # check the singleton class first
  class << self
    return workflow_spec if workflow_spec
  end

  c = self.class
  # using a simple loop instead of class_inheritable_accessor to avoid
  # dependency on Rails' ActiveSupport
  c = c.superclass until c.workflow_spec || !(c.include? Workflow)
  c.workflow_spec
end