class Pepito::Handler
Parent class for any handler Handlers
implement the logic for chat and http routes for the robot
Attributes
Config @return [Hash<>]
Currently running robot @return [Pepito::Robot]
Public Class Methods
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
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
Starts the handler @return [void]
# File lib/pepito/handler.rb, line 44 def start register_http_routes end
Private Instance Methods
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
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
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