Class: StateMachine::AlternateMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/call_center/state_machine_ext.rb

Overview

Extension for StateMachine::AlternateMachine 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.



68
69
70
# File 'lib/call_center/state_machine_ext.rb', line 68

def flow_stacks
  @flow_stacks
end

Instance Method Details

#actor(name, &blk) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/call_center/state_machine_ext.rb', line 90

def actor(name, &blk)
  (class << self; self; end).send(:define_method, name.to_sym) do |event_name, options|
    event_name = :"#{name}_#{event_name}"
    event(event_name, options)
  end
  @queued_sends << [[:flow_actors, name], blk]
end

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



84
85
86
87
88
# File 'lib/call_center/state_machine_ext.rb', line 84

def after(scope, options = {}, &blk)
  if @from_state
    @queued_sends << [[:after, @from_state, scope, options], blk]
  end
end

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



78
79
80
81
82
# File 'lib/call_center/state_machine_ext.rb', line 78

def before(scope, options = {}, &blk)
  if @from_state
    @queued_sends << [[:before, @from_state, scope, options], blk]
  end
end

#event_with_blocks(*args, &blk) ⇒ Object Also known as: event



98
99
100
101
102
103
104
105
106
# File 'lib/call_center/state_machine_ext.rb', line 98

def event_with_blocks(*args, &blk)
  options = args.extract_options!

  if flow_stacks && flow_stacks.any?
    options = flow_stacks.inject(options)
  end

  event_without_blocks(*args.push(options), &blk)
end

#flow_if(conditional, &blk) ⇒ Object



111
112
113
114
115
116
117
118
119
# File 'lib/call_center/state_machine_ext.rb', line 111

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



121
122
123
124
125
126
127
128
129
# File 'lib/call_center/state_machine_ext.rb', line 121

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(state_name = nil, &blk) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/call_center/state_machine_ext.rb', line 70

def response(state_name = nil, &blk)
  if @from_state
    @queued_sends << [[:response, @from_state], blk]
  else
    @queued_sends << [[:response, state_name], blk]
  end
end