Class: Huck::Handlers::ExecHandler
- Inherits:
-
Huck::Handler
- Object
- Huck::Handler
- Huck::Handlers::ExecHandler
- 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
Instance Method Summary collapse
-
#handle(msg) ⇒ Object
Handle an individual message by running an executable, passing in the gathered data via stdin.
-
#initialize ⇒ ExecHandler
constructor
Includes all required modules.
-
#verify_config ⇒ Object
Ensures that configuration is set properly before executing.
Methods inherited from Huck::Handler
Constructor Details
#initialize ⇒ ExecHandler
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_config ⇒ Object
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 |