Class: CallCenter::FlowCallback

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

Direct Known Subclasses

AfterFlowCallback

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options, 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 options[:uniq]
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block


3
4
5
# File 'lib/call_center/flow_callback.rb', line 3

def block
  @block
end

#scopeObject (readonly)

Returns the value of attribute scope


3
4
5
# File 'lib/call_center/flow_callback.rb', line 3

def scope
  @scope
end

#state_nameObject (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, options, block)
  case scope
  when :success
    new(state_name, scope, options, block).extend(SuccessFlowCallback)
  when :failure
    new(state_name, scope, options, block).extend(FailureFlowCallback)
  else
    new(state_name, scope, options, block).extend(AlwaysFlowCallback)
  end
end

Instance Method Details

#afterObject


45
46
47
# File 'lib/call_center/flow_callback.rb', line 45

def after
  false
end

#beforeObject


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

Returns:

  • (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