Class: CallCenter::FlowCallback
- Defined in:
- lib/call_center/flow_callback.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#state_name ⇒ Object
readonly
Returns the value of attribute state_name.
Class Method Summary collapse
Instance Method Summary collapse
- #after ⇒ Object
- #before ⇒ Object
-
#initialize(state_name, scope, options, block) ⇒ FlowCallback
constructor
A new instance of FlowCallback.
- #run(flow, transition) ⇒ Object
- #run_deferred?(call, transition) ⇒ Boolean
- #setup(context) ⇒ Object
Constructor Details
#initialize(state_name, scope, options, block) ⇒ FlowCallback
Returns a new instance of FlowCallback.
16 17 18 19 20 |
# File 'lib/call_center/flow_callback.rb', line 16 def initialize(state_name, scope, , block) raise "Invalid scope: #{scope} for flow callback" unless [:always, :success, :failure].include?(scope) @state_name, @scope, @block = state_name, scope, block extend(UniqueFlowCallback) if [:uniq] end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/call_center/flow_callback.rb', line 3 def block @block end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
3 4 5 |
# File 'lib/call_center/flow_callback.rb', line 3 def scope @scope end |
#state_name ⇒ Object (readonly)
Returns the value of attribute state_name.
3 4 5 |
# File 'lib/call_center/flow_callback.rb', line 3 def state_name @state_name end |
Class Method Details
.create(state_name, scope, options, block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/call_center/flow_callback.rb', line 5 def self.create(state_name, scope, , block) case scope when :success new(state_name, scope, , block).extend(SuccessFlowCallback) when :failure new(state_name, scope, , block).extend(FailureFlowCallback) else new(state_name, scope, , block).extend(AlwaysFlowCallback) end end |
Instance Method Details
#after ⇒ Object
45 46 47 |
# File 'lib/call_center/flow_callback.rb', line 45 def after false end |
#before ⇒ Object
41 42 43 |
# File 'lib/call_center/flow_callback.rb', line 41 def before true end |
#run(flow, transition) ⇒ Object
22 23 24 25 |
# File 'lib/call_center/flow_callback.rb', line 22 def run(flow, transition) @transition = transition flow.instance_exec(transition, &block) if should_run? end |
#run_deferred?(call, transition) ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/call_center/flow_callback.rb', line 27 def run_deferred?(call, transition) if call.respond_to?(:call_flow_callbacks_deferred?) && call.call_flow_callbacks_deferred? call.call_flow_defer_callback(self, transition) true end end |
#setup(context) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/call_center/flow_callback.rb', line 34 def setup(context) callback = self context.send(transition_hook, transition_parameters(context)) do |call, transition| callback.run(call, transition) unless callback.run_deferred?(call, transition) end end |