call_center 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
data/call_center.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{call_center}
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Henry Hsu"]
12
- s.date = %q{2011-10-25}
12
+ s.date = %q{2011-11-07}
13
13
  s.description = %q{Support for describing call center workflows}
14
14
  s.email = %q{hhsu@zendesk.com}
15
15
  s.extra_rdoc_files = [
@@ -5,11 +5,11 @@ module CallCenter
5
5
  def self.create(state_name, scope, options, block)
6
6
  case scope
7
7
  when :success
8
- FlowCallback.new(state_name, scope, options, block).extend(SuccessFlowCallback)
8
+ new(state_name, scope, options, block).extend(SuccessFlowCallback)
9
9
  when :failure
10
- FlowCallback.new(state_name, scope, options, block).extend(FailureFlowCallback)
10
+ new(state_name, scope, options, block).extend(FailureFlowCallback)
11
11
  else
12
- FlowCallback.new(state_name, scope, options, block).extend(AlwaysFlowCallback)
12
+ new(state_name, scope, options, block).extend(AlwaysFlowCallback)
13
13
  end
14
14
  end
15
15
 
@@ -26,22 +26,48 @@ module CallCenter
26
26
 
27
27
  def setup(context)
28
28
  callback = self
29
- context.before_transition(transition_parameters(context)) do |call, transition|
29
+ context.send(transition_hook, transition_parameters(context)) do |call, transition|
30
30
  callback.run(call, transition)
31
31
  end
32
32
  end
33
33
 
34
+ def before
35
+ true
36
+ end
37
+
38
+ def after
39
+ false
40
+ end
41
+
34
42
  private
35
43
 
36
44
  def transition_parameters(context)
37
45
  { context.any => @state_name }
38
46
  end
39
47
 
48
+ def transition_hook
49
+ :before_transition
50
+ end
51
+
40
52
  def should_run?
41
53
  true
42
54
  end
43
55
  end
44
56
 
57
+ class AfterFlowCallback < FlowCallback
58
+ def transition_hook
59
+ :after_transition
60
+ end
61
+
62
+ def before
63
+ false
64
+ end
65
+
66
+ def after
67
+ true
68
+ end
69
+ end
70
+
45
71
  module AlwaysFlowCallback
46
72
  def success; true; end
47
73
  def failure; true; end
@@ -1,8 +1,7 @@
1
1
  # Extension for StateMachine::Machine to store and provide render blocks
2
2
  class StateMachine::Machine
3
3
  attr_accessor :response_blocks
4
- attr_accessor :before_blocks
5
- attr_accessor :after_blocks
4
+ attr_accessor :callback_blocks
6
5
  attr_accessor :flow_actor_blocks
7
6
 
8
7
  def response(state_name, &blk)
@@ -11,13 +10,13 @@ class StateMachine::Machine
11
10
  end
12
11
 
13
12
  def before(state_name, scope, options, &blk)
14
- @before_blocks ||= []
15
- @before_blocks << CallCenter::FlowCallback.create(state_name, :always, options, blk)
13
+ @callback_blocks ||= []
14
+ @callback_blocks << CallCenter::FlowCallback.create(state_name, :always, options, blk)
16
15
  end
17
16
 
18
17
  def after(state_name, scope, options, &blk)
19
- @after_blocks ||= []
20
- @after_blocks << CallCenter::FlowCallback.create(state_name, scope, options, blk)
18
+ @callback_blocks ||= []
19
+ @callback_blocks << CallCenter::AfterFlowCallback.create(state_name, scope, options, blk)
21
20
  end
22
21
 
23
22
  def block_accessor(accessor, for_state)
@@ -32,25 +31,23 @@ class StateMachine::Machine
32
31
  end
33
32
 
34
33
  def setup_call_flow(flow)
35
- setup_before_blocks
36
- setup_after_blocks
34
+ setup_success_blocks
35
+ setup_failure_blocks
37
36
  setup_flow_actor_blocks(flow)
38
37
  self
39
38
  end
40
39
 
41
- def setup_before_blocks
42
- return unless @before_blocks
43
- @before_blocks.each { |callback| callback.setup(self) }
40
+ def setup_success_blocks
41
+ return unless @callback_blocks
42
+ @callback_blocks.select { |c| c.before || (c.success && c.after) }.each { |callback| callback.setup(self) }
44
43
  end
45
44
 
46
- def setup_after_blocks
47
- return unless @after_blocks
48
- @after_blocks.select(&:success).each { |callback| callback.setup(self) }
49
-
45
+ def setup_failure_blocks
46
+ return unless @callback_blocks
50
47
  event_names = events.map(&:name)
51
48
  event_names.each do |event_name|
52
49
  after_failure :on => event_name do |call, transition|
53
- callbacks = @after_blocks.select { |callback| callback.state_name == transition.to_name && callback.failure } || []
50
+ callbacks = @callback_blocks.select { |callback| callback.after && callback.state_name == transition.to_name && callback.failure } || []
54
51
  callbacks.each { |callback| callback.run(call, transition) }
55
52
  end
56
53
  end
@@ -130,7 +130,7 @@ class CallCenterTest < Test::Unit::TestCase
130
130
  assert_select "Response"
131
131
  end
132
132
 
133
- should "execute before callbacks" do
133
+ should "execute callbacks" do
134
134
  @call.state = 'cancelled'
135
135
 
136
136
  @call.expects(:notify).with(:before_always).times(3)
@@ -150,6 +150,22 @@ class CallCenterTest < Test::Unit::TestCase
150
150
  assert(!@call.customer_hangs_up)
151
151
  end
152
152
 
153
+ should "execute callbacks in sequence" do
154
+ seq = sequence('callback_sequence')
155
+ @call.state = 'cancelled'
156
+
157
+ @call.expects(:notify).with(:before_always).in_sequence(seq)
158
+ @call.expects(:notify).with(:before_always_uniq).in_sequence(seq)
159
+
160
+ @call.expects(:notify).with(:after_always).in_sequence(seq)
161
+ @call.expects(:notify).with(:after_success).in_sequence(seq)
162
+
163
+ @call.expects(:notify).with(:after_always_uniq).in_sequence(seq)
164
+ @call.expects(:notify).with(:after_success_uniq, anything).in_sequence(seq)
165
+
166
+ @call.customer_end!
167
+ end
168
+
153
169
  should "asynchronously perform event" do
154
170
  @call.stubs(:agents_available?).returns(true)
155
171
  @call.incoming_call!
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: call_center
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Henry Hsu
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-25 00:00:00 -07:00
18
+ date: 2011-11-07 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency