Class: Aws::Lex::Conversation::Handler::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/lex/conversation/handler/base.rb

Direct Known Subclasses

Delegate, Echo, SlotResolution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Base

Returns a new instance of Base.



10
11
12
13
# File 'lib/aws/lex/conversation/handler/base.rb', line 10

def initialize(opts = {})
  self.successor = opts[:successor]
  self.options = opts[:options] || {}
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/aws/lex/conversation/handler/base.rb', line 8

def options
  @options
end

#successorObject

Returns the value of attribute successor.



8
9
10
# File 'lib/aws/lex/conversation/handler/base.rb', line 8

def successor
  @successor
end

Instance Method Details

#handle(conversation) ⇒ Object



24
25
26
27
28
29
# File 'lib/aws/lex/conversation/handler/base.rb', line 24

def handle(conversation)
  return response(conversation) if will_respond?(conversation)
  return unless successor # end of chain - return nil

  successor.handle(conversation)
end

#response(_conversation) ⇒ Object

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/aws/lex/conversation/handler/base.rb', line 20

def response(_conversation)
  raise NotImplementedError, 'define #response in a subclass'
end

#will_respond?(conversation) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/aws/lex/conversation/handler/base.rb', line 15

def will_respond?(conversation)
  callable = options.fetch(:respond_on) { ->(_c) { false } }
  callable.call(conversation)
end