Class: Foreman::Process
- Inherits:
-
Object
- Object
- Foreman::Process
- Defined in:
- lib/foreman/process.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
-
#cwd ⇒ Object
Returns the working directory for this
Process
. -
#exec(options = {}) ⇒ Object
Exec a
Process
. -
#expanded_command(custom_env = {}) ⇒ String
Get environment-expanded command for a
Process
. -
#initialize(command, options = {}) ⇒ Process
constructor
Create a Process.
-
#run(options = {}) ⇒ Object
Run a
Process
.
Constructor Details
#initialize(command, options = {}) ⇒ Process
Create a Process
17 18 19 20 21 22 |
# File 'lib/foreman/process.rb', line 17 def initialize(command, ={}) @command = command @options = .dup @options[:env] ||= {} end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/foreman/process.rb', line 6 def command @command end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/foreman/process.rb', line 7 def env @env end |
Instance Method Details
#cwd ⇒ Object
Returns the working directory for this Process
76 77 78 |
# File 'lib/foreman/process.rb', line 76 def cwd File.(@options[:cwd] || ".") end |
#exec(options = {}) ⇒ Object
Exec a Process
65 66 67 68 69 70 |
# File 'lib/foreman/process.rb', line 65 def exec(={}) env = @options[:env].merge([:env] || {}) env.each { |k, v| ENV[k] = v } Dir.chdir(cwd) Kernel.exec (env) end |
#expanded_command(custom_env = {}) ⇒ String
Get environment-expanded command for a Process
30 31 32 33 34 35 36 37 |
# File 'lib/foreman/process.rb', line 30 def (custom_env={}) env = @options[:env].merge(custom_env) = command.dup env.each do |key, val| .gsub!("$#{key}", val) end end |
#run(options = {}) ⇒ Object
Run a Process
48 49 50 51 52 53 54 55 56 |
# File 'lib/foreman/process.rb', line 48 def run(={}) env = @options[:env].merge([:env] || {}) output = [:output] || $stdout runner = "#{Foreman.runner}".shellescape Dir.chdir(cwd) do Process.spawn env, (env), :out => output, :err => output end end |