Class: Huck::Handlers::ExecHandler

Inherits:
Huck::Handler show all
Defined in:
lib/huck/handlers/exec.rb

Overview

A handler to execute arbitrary scripts, passing in the generated text as input on stdin.

Instance Attribute Summary

Attributes inherited from Huck::Handler

#config

Instance Method Summary collapse

Methods inherited from Huck::Handler

factory

Constructor Details

#initializeExecHandler

Includes all required modules



10
11
12
# File 'lib/huck/handlers/exec.rb', line 10

def initialize
  Huck::must_load 'open3'
end

Instance Method Details

#handle(msg) ⇒ Object

Handle an individual message by running an executable, passing in the gathered data via stdin.

Parameters:

msg

The message to process



28
29
30
31
32
33
34
# File 'lib/huck/handlers/exec.rb', line 28

def handle msg
  verify_config

  Open3.popen2 @config['command'] do |stdin, _, _|
    stdin.print msg
  end
end

#verify_configObject

Ensures that configuration is set properly before executing



15
16
17
18
19
# File 'lib/huck/handlers/exec.rb', line 15

def verify_config
  if !@config.has_key? 'command'
    raise Huck::Error, 'missing "exec" generator config: "command"'
  end
end