Class: Workflow::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/workflow/event.rb

Defined Under Namespace

Classes: Conditions, Transition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, meta) ⇒ Event

Returns a new instance of Event.



5
6
7
8
9
# File 'lib/workflow/event.rb', line 5

def initialize(name, meta)
  @name = name.to_sym
  @transitions = []
  @meta = meta || {}
end

Instance Attribute Details

#metaObject (readonly)

Returns the value of attribute meta.



3
4
5
# File 'lib/workflow/event.rb', line 3

def meta
  @meta
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/workflow/event.rb', line 3

def name
  @name
end

#transitionsObject (readonly)

Returns the value of attribute transitions.



3
4
5
# File 'lib/workflow/event.rb', line 3

def transitions
  @transitions
end

Instance Method Details

#evaluate(target) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/workflow/event.rb', line 15

def evaluate(target)
  transition = transitions.find{|t| t.apply? target}
  if transition
    return transition.target_state
  else
    nil
  end
end

#inspectObject



11
12
13
# File 'lib/workflow/event.rb', line 11

def inspect
  "<Event name=#{name.inspect} transitions(#{transitions.length})=#{transitions.inspect}>"
end

#to(target_state, **conditions_def, &block) ⇒ Object



24
25
26
27
# File 'lib/workflow/event.rb', line 24

def to(target_state, **conditions_def, &block)
  conditions = Conditions.new &&conditions_def, block
  self.transitions << Transition.new(target_state, conditions_def, &block)
end