class Pepito::Handler

Parent class for any handler Handlers implement the logic for chat and http routes for the robot

Attributes

config[R]

Config @return [Hash<>]

robot[R]

Currently running robot @return [Pepito::Robot]

Public Class Methods

configs() click to toggle source

Configs for the handler, method should be overriden in the handler if parameters are necessary @return [Array<Hash>] Array of hashes with the config parameters

# File lib/pepito/handler.rb, line 15
def configs
  [{}]
end
new(robot, config) click to toggle source

Initializes the Adapter class @param robot [Pepito::Robot] The currently running robot @return [void]

# File lib/pepito/handler.rb, line 31
def initialize(robot, config)
  @robot = robot
  @config = config

  begin
    missing_configuration_values
  rescue => e
    raise e
  end
end

Public Instance Methods

start() click to toggle source

Starts the handler @return [void]

# File lib/pepito/handler.rb, line 44
def start
  register_http_routes
end

Private Instance Methods

configuration_value?(name) click to toggle source

Whether a configuration_value is present or not. @return [Boolean] True if is present, False otherwise.

# File lib/pepito/handler.rb, line 71
def configuration_value?(name)
  !@config.nil? && @config.keys.include?(name) && !@config[name].nil? && !@config[name].empty?
end
missing_configuration_values() click to toggle source

Check whether all required configuration values exist Raises a [Pepito::Errors::MissingConfigurationValueError] if methods are missing @return [void]

# File lib/pepito/handler.rb, line 61
def missing_configuration_values
  confs = []
  self.class.configs.each do |c|
    confs << c[:name] if c[:required] && !configuration_value?(c[:name])
  end
  raise Errors::MissingConfigurationValueError.new(confs), 'missing required configuration values' unless confs.empty?
end
register_http_routes() click to toggle source

Registers handler’s http routes to the http_api @return [void]

# File lib/pepito/handler.rb, line 52
def register_http_routes
  @http_routes.each do |route|
    @robot.http_api.router.add_route(route.route)
  end if @http_routes
end