class Fudge::Tasks::SubProcess
Allow use of shell commands as tasks.
Unlike Fudge::Shell, this task will not spawn a new shell.
Allows the caller to set environment variables for the process, and to specify process attributes, as with Process::Spawn.
The constructor and {#run run
} method each accept two new options, {#environment :environment} and {#spawn_options :spawn_options}.
Attributes
environment[RW]
@!attribute environment
@return [Hash] environment variables to be set for the process; the keys are strings, corresponding to the variables' names (case sensitive).
spawn_options[RW]
@!attribute spawn_options
@return [Hash] attributes for the spawned process (see Ruby's Process::spawn documentation for details)
Private Instance Methods
cmd(options={})
click to toggle source
Defines the command to run
# File lib/fudge/tasks/sub_process.rb, line 31 def cmd(options={}) env = merge_option(:environment, options) spawn_options = merge_option(:spawn_options, options) mk_cmd(env, arguments, spawn_options) end
merge_option(key, options)
click to toggle source
Merges the option hash set when the task was create with that passed in on this run.
# File lib/fudge/tasks/sub_process.rb, line 39 def merge_option(key, options) my_options = self.send(key) || {} my_options.merge(options[key] || {}) end
mk_cmd(env, cmd, options)
click to toggle source
Make the command for IO::popen, by splitting the command line into an array and adding the environment variables and spawn options.
# File lib/fudge/tasks/sub_process.rb, line 46 def mk_cmd(env, cmd, options) [env, cmd.shellsplit, options].flatten end