class Slackify::Handlers::Factory

Creates the handler structs

Public Class Methods

for(configuration) click to toggle source
# File lib/slackify/handlers/factory.rb, line 7
def self.for(configuration)
  Validator.verify_handler_integrity(configuration)

  handler = OpenStruct.new
  handler.name = configuration.keys.first
  handler.commands = []

  configuration[handler.name]['commands']&.each do |command|
    built_command = OpenStruct.new
    built_command.regex = command['regex']
    built_command.handler = handler.name.camelize.constantize.method(command['action'])
    built_command.description = command['description']
    built_command.parameters = command['parameters']
    built_command.base_command = command['base_command']
    handler.commands << built_command.freeze
  end

  handler.commands.freeze
  handler.freeze
end