Class: Huck::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/huck/handler.rb

Overview

Base handler class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/huck/handler.rb', line 5

def config
  @config
end

Class Method Details

.factory(kwargs = {}) ⇒ Object

Given a handler’s name (or no name), return a new handler instance

Parameters:

name

The name of the handler, or nil to guess

config

A configuration hash

Returns:

A Huck::Handler instance



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/huck/handler.rb', line 18

def self.factory kwargs = {}
  name = Huck::getarg kwargs, :name, nil
  config = Huck::getarg kwargs, :config, nil

  name = 'echo' if name.nil?

  case name
  when 'echo'
    h = Handlers::EchoHandler.new
  when 'exec'
    h = Handlers::ExecHandler.new
  else
    raise RuntimeError, "bad handler: #{name}"
  end

  h.config = config
  return h
end