Class: StateMachine::StateContext
- Includes:
- MatcherHelpers
- Defined in:
- lib/call_center/state_machine_ext.rb
Overview
Extension for StateMachine::StateContext to provide render blocks inside a state definition
Instance Attribute Summary collapse
-
#flow_stacks ⇒ Object
Returns the value of attribute flow_stacks.
Instance Method Summary collapse
- #after(scope, options = {}, &blk) ⇒ Object
- #before(scope, options = {}, &blk) ⇒ Object
- #event(name, options = {}) ⇒ Object
- #flow_if(conditional, &blk) ⇒ Object
- #flow_unless(conditional, &blk) ⇒ Object
- #response(&blk) ⇒ Object
Instance Attribute Details
#flow_stacks ⇒ Object
Returns the value of attribute flow_stacks.
88 89 90 |
# File 'lib/call_center/state_machine_ext.rb', line 88 def flow_stacks @flow_stacks end |
Instance Method Details
#after(scope, options = {}, &blk) ⇒ Object
106 107 108 |
# File 'lib/call_center/state_machine_ext.rb', line 106 def after(scope, = {}, &blk) machine.after(state.name, scope, , &blk) end |
#before(scope, options = {}, &blk) ⇒ Object
102 103 104 |
# File 'lib/call_center/state_machine_ext.rb', line 102 def before(scope, = {}, &blk) machine.before(state.name, scope, , &blk) end |
#event(name, options = {}) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/call_center/state_machine_ext.rb', line 90 def event(name, = {}) if flow_stacks && flow_stacks.any? = flow_stacks.inject() end transition(.update(:on => name)) end |
#flow_if(conditional, &blk) ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/call_center/state_machine_ext.rb', line 110 def flow_if(conditional, &blk) self.flow_stacks ||= CallCenter::ConditionalStack.new begin self.flow_stacks << CallCenter::ConditionalStack::IfConditional.new(conditional) yield if block_given? ensure self.flow_stacks.pop end end |
#flow_unless(conditional, &blk) ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/call_center/state_machine_ext.rb', line 120 def flow_unless(conditional, &blk) self.flow_stacks ||= CallCenter::ConditionalStack.new begin self.flow_stacks << CallCenter::ConditionalStack::UnlessConditional.new(conditional) yield if block_given? ensure self.flow_stacks.pop end end |
#response(&blk) ⇒ Object
98 99 100 |
# File 'lib/call_center/state_machine_ext.rb', line 98 def response(&blk) machine.response(state.name, &blk) end |