Class: StateMachine::StateContext

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#flow_stacksObject

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, options = {}, &blk)
  machine.after(state.name, scope, options, &blk)
end

#before(scope, options = {}, &blk) ⇒ Object


102
103
104
# File 'lib/call_center/state_machine_ext.rb', line 102

def before(scope, options = {}, &blk)
  machine.before(state.name, scope, options, &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, options = {})
  if flow_stacks && flow_stacks.any?
    options = flow_stacks.inject(options)
  end

  transition(options.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