module TestWorkflow

Constants

VERSION

Public Class Methods

caller() click to toggle source
# File lib/test_workflow.rb, line 23
def self.caller
  @caller
end
included(caller) click to toggle source
# File lib/test_workflow.rb, line 18
def self.included(caller)
  caller.extend Paths
  @caller = caller
end

Public Instance Methods

continue_path_to(context, keys = { using: :default }, &block) click to toggle source

Provides an execution path that starts execution of a given path from the standpoint of the “current context”, which is something that must be set as part of execution logic.

# File lib/test_workflow.rb, line 50
def continue_path_to(context, keys = { using: :default }, &block)
  path = workflow_path_for(keys)
  path_start = find_index_for(path, @current_context.class)
  path_end = find_index_for(path, context) - 1

  if path_start == path_end
    execute_path([path[path_start]], false)
  else
    execute_path(path[path_start..path_end], false)
  end

  on(context, &block)
end
entire_path(keys = { using: :default, visit: false }) click to toggle source

Provides an execution path for an entire workflow path.

# File lib/test_workflow.rb, line 65
def entire_path(keys = { using: :default, visit: false })
  path_workflow = workflow_path_for(keys)
  execute_path(path_workflow[0..-1], keys[:visit])
end
Also aliased as: run_entire_path, run_full_path
path_to(context, keys = { using: :default, visit: false }, &block) click to toggle source

Provides an execution path for a given workflow path, using a specific definition that is part of that workflow path.

# File lib/test_workflow.rb, line 29
def path_to(context, keys = { using: :default, visit: false }, &block)
  keys[:using] = :default unless keys[:using]
  keys[:visit] = false unless keys[:visit]

  path, path_goal = path_trail(keys, context)

  return on(context, &block) if path_goal == -1

  path_start = keys[:from] ? path_start_point(path, keys) : 0
  execute_path(path[path_start..path_goal], keys[:visit])

  on(context, &block)
end
path_up_to(context, keys = { using: :default, visit: false }, &block)
Alias for: path_to
run_entire_path(keys = { using: :default, visit: false })
Alias for: entire_path
run_full_path(keys = { using: :default, visit: false })
Alias for: entire_path
workflow_to(context, keys = { using: :default, visit: false }, &block)
Alias for: path_to
workflow_up_to(context, keys = { using: :default, visit: false }, &block)
Alias for: path_to

Private Instance Methods

execute_path(path, visit) click to toggle source
# File lib/test_workflow.rb, line 91
def execute_path(path, visit)
  path.each do |definition, action, *args|
    context = visit ? visit(definition) : on(definition)
    visit = false

    unless context.respond_to?(action)
      raise("Path action '#{action}' not defined on '#{definition}'.")
    end

    context.__send__ action unless args
    context.__send__ action, *args if args
  end
end
find_index_for(path, context) click to toggle source
# File lib/test_workflow.rb, line 105
def find_index_for(path, context)
  path.find_index { |item| item[0] == context }
end
path_start_point(path, keys) click to toggle source
# File lib/test_workflow.rb, line 81
def path_start_point(path, keys)
  path.find_index { |item| item[0] == keys[:from] }
end
path_trail(keys, context) click to toggle source
# File lib/test_workflow.rb, line 75
def path_trail(keys, context)
  path = workflow_path_for(keys)
  goal = find_index_for(path, context) - 1
  [path, goal]
end
workflow_path_for(keys) click to toggle source
# File lib/test_workflow.rb, line 85
def workflow_path_for(keys)
  path = TestWorkflow.caller.paths[keys[:using]]
  raise("The path named '#{keys[:using]}' was not found.") unless path
  path
end