Class: Bas::Bot::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bas/bot/base.rb

Overview

The Bot::Base class serves as the foundation for implementing specific bots. Operating as an interface, this class defines essential attributes and methods, providing a blueprint for creating custom bots formed by a Read, Process, and Write components.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, shared_storage_reader, shared_storage_writer = nil) ⇒ Base

Returns a new instance of Base.



17
18
19
20
21
22
# File 'lib/bas/bot/base.rb', line 17

def initialize(options, shared_storage_reader, shared_storage_writer = nil)
  default_options = { close_connections_after_process: true }
  @process_options = default_options.merge(options || {})
  @shared_storage_reader = shared_storage_reader
  @shared_storage_writer = shared_storage_writer || shared_storage_reader
end

Instance Attribute Details

#process_optionsObject (readonly)

Returns the value of attribute process_options.



14
15
16
# File 'lib/bas/bot/base.rb', line 14

def process_options
  @process_options
end

#process_responseObject

Returns the value of attribute process_response.



15
16
17
# File 'lib/bas/bot/base.rb', line 15

def process_response
  @process_response
end

#read_responseObject

Returns the value of attribute read_response.



15
16
17
# File 'lib/bas/bot/base.rb', line 15

def read_response
  @read_response
end

#shared_storage_readerObject (readonly)

Returns the value of attribute shared_storage_reader.



14
15
16
# File 'lib/bas/bot/base.rb', line 14

def shared_storage_reader
  @shared_storage_reader
end

#shared_storage_writerObject (readonly)

Returns the value of attribute shared_storage_writer.



14
15
16
# File 'lib/bas/bot/base.rb', line 14

def shared_storage_writer
  @shared_storage_writer
end

#write_responseObject

Returns the value of attribute write_response.



15
16
17
# File 'lib/bas/bot/base.rb', line 15

def write_response
  @write_response
end

Instance Method Details

#executeObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bas/bot/base.rb', line 24

def execute
  @read_response = read

  @shared_storage_reader.set_in_process

  @process_response = process
  raise Utils::Exceptions::InvalidProcessResponse unless process_response.is_a?(Hash)

  @shared_storage_reader.set_processed

  @write_response = write

  close_connections if @process_options[:close_connections_after_process].eql?(true)

  @write_response
end