Class: Huck::Generators::ExecGenerator

Inherits:
Huck::Generator show all
Defined in:
lib/huck/generators/exec.rb

Overview

A generator to execute arbitrary scripts and use their output

Instance Attribute Summary

Attributes inherited from Huck::Generator

#config

Instance Method Summary collapse

Methods inherited from Huck::Generator

factory

Constructor Details

#initializeExecGenerator

Includes all required modules



9
10
11
# File 'lib/huck/generators/exec.rb', line 9

def initialize
  Huck::must_load 'open3'
end

Instance Method Details

#generateObject

Generate data by running a command and collecting output



21
22
23
24
25
26
27
28
# File 'lib/huck/generators/exec.rb', line 21

def generate
  verify_config

  Open3.popen2e @config['command'] do |_, output, thread|
    thread.value # wait for process to complete
    return output.read
  end
end

#verify_configObject

Ensures that configuration is set properly before executing



14
15
16
17
18
# File 'lib/huck/generators/exec.rb', line 14

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