Class: FlowChat::Ussd::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_chat/ussd/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) {|_self| ... } ⇒ Processor

Returns a new instance of Processor.

Yields:

  • (_self)

Yield Parameters:



8
9
10
11
12
13
14
# File 'lib/flow_chat/ussd/processor.rb', line 8

def initialize(controller)
  @context = FlowChat::Context.new
  @context["controller"] = controller
  @middleware = ::Middleware::Builder.new(name: "ussd.middleware")

  yield self if block_given?
end

Instance Attribute Details

#gatewayObject (readonly)

Returns the value of attribute gateway.



6
7
8
# File 'lib/flow_chat/ussd/processor.rb', line 6

def gateway
  @gateway
end

#middlewareObject (readonly)

Returns the value of attribute middleware.



6
7
8
# File 'lib/flow_chat/ussd/processor.rb', line 6

def middleware
  @middleware
end

Instance Method Details

#run(flow_class, action) {|stack| ... } ⇒ Object

Yields:

  • (stack)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/flow_chat/ussd/processor.rb', line 36

def run(flow_class, action)
  @context["flow.name"] = flow_class.name.underscore
  @context["flow.class"] = flow_class
  @context["flow.action"] = action

  stack = ::Middleware::Builder.new name: "ussd" do |b|
    b.use gateway
    b.use FlowChat::Session::Middleware
    b.use FlowChat::Ussd::Middleware::Pagination
    b.use middleware
    b.use FlowChat::Ussd::Middleware::Executor
  end.inject_logger(Rails.logger)

  yield stack if block_given?

  stack.call(@context)
end

#use_gateway(gateway) ⇒ Object



16
17
18
19
# File 'lib/flow_chat/ussd/processor.rb', line 16

def use_gateway(gateway)
  @gateway = gateway
  self
end

#use_middleware(middleware) ⇒ Object



26
27
28
29
# File 'lib/flow_chat/ussd/processor.rb', line 26

def use_middleware(middleware)
  @middleware.use middleware
  self
end

#use_resumable_sessionsObject



31
32
33
34
# File 'lib/flow_chat/ussd/processor.rb', line 31

def use_resumable_sessions
  middleware.insert_before 0, FlowChat::Ussd::Middleware::ResumableSession
  self
end

#use_session_store(session_store) ⇒ Object



21
22
23
24
# File 'lib/flow_chat/ussd/processor.rb', line 21

def use_session_store(session_store)
  @context["session.store"] = session_store
  self
end