class Workflow::Event

Attributes

action[RW]
condition[RW]
meta[RW]
name[RW]
transitions_to[RW]

Public Class Methods

new(name, transitions_to, condition = nil, meta = {}, &action) click to toggle source
# File lib/workflow/event.rb, line 6
def initialize(name, transitions_to, condition = nil, meta = {}, &action)
  @name = name
  @transitions_to = transitions_to.to_sym
  @meta = meta
  @action = action
  @condition = if condition.nil? || condition.is_a?(Symbol) || condition.respond_to?(:call)
                 condition
               else
                 raise TypeError, 'condition must be nil, an instance method name symbol or a callable (eg. a proc or lambda)'
               end
end

Public Instance Methods

condition_applicable?(object) click to toggle source
# File lib/workflow/event.rb, line 18
def condition_applicable?(object)
  if condition
    if condition.is_a?(Symbol)
      object.send(condition)
    else
      condition.call(object)
    end
  else
    true
  end
end
draw(graph, from_state) click to toggle source
# File lib/workflow/event.rb, line 30
def draw(graph, from_state)
  graph.add_edges(from_state.name.to_s, transitions_to.to_s, meta.merge(:label => to_s))
end
to_s() click to toggle source
# File lib/workflow/event.rb, line 34
def to_s
  @name.to_s
end