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.



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

def callbacks
  @callbacks
end

Instance Method Details

#after_save(*args, &block) ⇒ Object



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

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

#after_transition(*args, &block) ⇒ Object



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

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

#before_save(*args, &block) ⇒ Object



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

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



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

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

#state(state_class) ⇒ Object



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

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



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

def state_attribute(method)
  @state_attribute = method
end

#state_methodObject



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

def state_method
  @state_attribute || :state
end

#state_namesObject



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

def state_names
  states.keys.map(&:to_s)
end

#statesObject



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

def states
  @states ||= {}
end