class Pepito::Adapter

Parent class for any adapter Adapters allow to communicate with the bot from differente platforms.

Constants

REQUIRED_METHODS

List of required methods for adapters

Attributes

config[R]

Config hash for the adapter @return [Hash<String,String>]

robot[R]

The currently running robot @return [Pepito::Robot]

Public Class Methods

configs() click to toggle source

Configs for the adapter, override this method in the adapter @return [Array<Hash>] Array of strings with the config parameters

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

Initializes the Adapter class @param robot [Pepito::Robot] The currently running robot @param config [Hash<String,String>] The config for the adapter @return [void]

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

  begin
    missing_methods
    missing_configuration_values
  rescue => e
    raise e
  end
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/adapter.rb, line 97
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/adapter.rb, line 87
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
missing_methods() click to toggle source

Check whether all required methods are implemented Raises a [Pepito::Errors::RequiredMethodsError] if methods are missing @return [void]

# File lib/pepito/adapter.rb, line 76
def missing_methods
  methods = []
  REQUIRED_METHODS.each do |method|
    methods << method unless self.methods.include?(method)
  end
  raise Errors::RequiredMethodsError.new(methods), 'missing required methods' unless methods.empty?
end