call_center 1.0.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,10 +37,7 @@ module CallCenter
37
37
  module ClassMethods
38
38
  attr_accessor :call_flow_state_machine_name
39
39
 
40
- # Calls state_machine ... with :syntax => :alternate
41
40
  def call_flow(*args, &blk)
42
- options = args.last.is_a?(Hash) ? args.pop : {}
43
- args << options.merge(:syntax => :alternate)
44
41
  state_machine_name = args.first || :state
45
42
  if state_machine = CallCenter.cached(self, state_machine_name)
46
43
  state_machine = state_machine.duplicate_to(self)
@@ -19,6 +19,14 @@ class StateMachine::Machine
19
19
  @callback_blocks << CallCenter::AfterFlowCallback.create(state_name, scope, options, blk)
20
20
  end
21
21
 
22
+ def actor(name, &blk)
23
+ StateMachine::StateContext.send(:define_method, name.to_sym) do |event_name, options|
24
+ event_name = :"#{name}_#{event_name}"
25
+ event(event_name, options)
26
+ end
27
+ flow_actors(name, &blk)
28
+ end
29
+
22
30
  def block_accessor(accessor, for_state)
23
31
  return unless respond_to?(accessor)
24
32
  blocks = send(accessor)
@@ -61,53 +69,44 @@ class StateMachine::Machine
61
69
  end
62
70
  end
63
71
  end
72
+
73
+ def duplicate_to(clazz)
74
+ new_copy = self.clone
75
+ new_copy.owner_class = clazz
76
+ new_copy.define_helpers
77
+ new_copy.define_scopes(@plural)
78
+ new_copy.events.each { |event| event.send(:add_actions) }
79
+ new_copy.states.each { |state| state.send(:add_predicate) }
80
+ new_copy
81
+ end
64
82
  end
65
83
 
66
- # Extension for StateMachine::AlternateMachine to provide render blocks inside a state definition
67
- class StateMachine::AlternateMachine
84
+ # Extension for StateMachine::StateContext to provide render blocks inside a state definition
85
+ class StateMachine::StateContext
86
+ include StateMachine::MatcherHelpers
87
+
68
88
  attr_accessor :flow_stacks
69
89
 
70
- def response(state_name = nil, &blk)
71
- if @from_state
72
- @queued_sends << [[:response, @from_state], blk]
73
- else
74
- @queued_sends << [[:response, state_name], blk]
90
+ def event(name, options = {})
91
+ if flow_stacks && flow_stacks.any?
92
+ options = flow_stacks.inject(options)
75
93
  end
76
- end
77
94
 
78
- def before(scope, options = {}, &blk)
79
- if @from_state
80
- @queued_sends << [[:before, @from_state, scope, options], blk]
81
- end
95
+ transition(options.update(:on => name))
82
96
  end
83
97
 
84
- def after(scope, options = {}, &blk)
85
- if @from_state
86
- @queued_sends << [[:after, @from_state, scope, options], blk]
87
- end
98
+ def response(&blk)
99
+ machine.response(state.name, &blk)
88
100
  end
89
101
 
90
- def actor(name, &blk)
91
- (class << self; self; end).send(:define_method, name.to_sym) do |event_name, options|
92
- event_name = :"#{name}_#{event_name}"
93
- event(event_name, options)
94
- end
95
- @queued_sends << [[:flow_actors, name], blk]
102
+ def before(scope, options = {}, &blk)
103
+ machine.before(state.name, scope, options, &blk)
96
104
  end
97
105
 
98
- def event_with_blocks(*args, &blk)
99
- options = args.extract_options!
100
-
101
- if flow_stacks && flow_stacks.any?
102
- options = flow_stacks.inject(options)
103
- end
104
-
105
- event_without_blocks(*args.push(options), &blk)
106
+ def after(scope, options = {}, &blk)
107
+ machine.after(state.name, scope, options, &blk)
106
108
  end
107
109
 
108
- alias_method :event_without_blocks, :event
109
- alias_method :event, :event_with_blocks
110
-
111
110
  def flow_if(conditional, &blk)
112
111
  self.flow_stacks ||= CallCenter::ConditionalStack.new
113
112
  begin
@@ -31,9 +31,8 @@ module CallCenter
31
31
  html_document.root
32
32
  end
33
33
 
34
- alias_method_chain :response_from_page_or_rjs, :body
35
- elsif instance_methods.include?(:response_from_page_with_rjs) # prototype-rails hacks we do not want
36
- alias_method :response_from_page, :response_from_page_without_rjs
34
+ alias_method :response_from_page_or_rjs_without_body, :response_from_page_or_rjs
35
+ alias_method :response_from_page_or_rjs, :response_from_page_or_rjs_with_body
37
36
  end
38
37
  end
39
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: call_center
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-28 00:00:00.000000000 Z
12
+ date: 2013-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -28,13 +28,13 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: hsume2-state_machine
31
+ name: state_machine
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 1.0.5
37
+ version: 1.2.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 1.0.5
45
+ version: 1.2.0
46
46
  description: Support for describing call center workflows
47
47
  email: hhsu@zendesk.com
48
48
  executables: []
@@ -72,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
72
  version: '0'
73
73
  segments:
74
74
  - 0
75
- hash: 1218219557821151233
75
+ hash: 1830209325971150874
76
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  none: false
78
78
  requirements:
@@ -81,10 +81,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  segments:
83
83
  - 0
84
- hash: 1218219557821151233
84
+ hash: 1830209325971150874
85
85
  requirements: []
86
86
  rubyforge_project:
87
- rubygems_version: 1.8.25
87
+ rubygems_version: 1.8.24
88
88
  signing_key:
89
89
  specification_version: 3
90
90
  summary: Support for describing call center workflows