Module: FlowMachine::Workflow::ClassMethods

Defined in:
lib/flow_machine/workflow.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#callbacksObject

Returns the value of attribute callbacks.



18
19
20
# File 'lib/flow_machine/workflow.rb', line 18

def callbacks
  @callbacks
end

Instance Method Details

#after_save(*args, &block) ⇒ Object



58
59
60
# File 'lib/flow_machine/workflow.rb', line 58

def after_save(*args, &block)
  add_callback(:after_save, FlowMachine::Callback.new(*args, &block))
end

#after_transition(*args, &block) ⇒ Object



62
63
64
# File 'lib/flow_machine/workflow.rb', line 62

def after_transition(*args, &block)
  add_callback(:after_transition, FlowMachine::Callback.new(*args, &block))
end

#before_save(*args, &block) ⇒ Object



54
55
56
# File 'lib/flow_machine/workflow.rb', line 54

def before_save(*args, &block)
  add_callback(:before_save, FlowMachine::Callback.new(*args, &block))
end

#refresh_state_methods!Object

Mainly to be used in testing, call this method to ensure that any dynamically created state methods get exposed to the workflow



30
31
32
33
34
# File 'lib/flow_machine/workflow.rb', line 30

def refresh_state_methods!
  states.values.each do |state_class|
    add_state_methods_from(state_class)
  end
end

#state(state_class) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/flow_machine/workflow.rb', line 36

def state(state_class)
  name = get_state_name(state_class)
  states[name] = state_class
  add_state_methods_from(state_class)

  define_method "#{name}?" do
    current_state_name.to_s == name.to_s
  end
end

#state_attribute(method) ⇒ Object



46
47
48
# File 'lib/flow_machine/workflow.rb', line 46

def state_attribute(method)
  @state_attribute = method
end

#state_methodObject



50
51
52
# File 'lib/flow_machine/workflow.rb', line 50

def state_method
  @state_attribute || :state
end

#state_namesObject



20
21
22
# File 'lib/flow_machine/workflow.rb', line 20

def state_names
  states.keys.map &:to_s
end

#statesObject



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

def states
  @states ||= {}
end