Class: Foruiman::Process
- Inherits:
-
Object
- Object
- Foruiman::Process
- Defined in:
- lib/foruiman/process.rb
Overview
Adapted from Foreman::Process. Expansion belongs to the shell, not Ruby.
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#cwd ⇒ Object
readonly
Returns the value of attribute cwd.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
-
#initialize(command, options = {}) ⇒ Process
constructor
A new instance of Process.
- #run(options = {}) ⇒ Object
Constructor Details
#initialize(command, options = {}) ⇒ Process
Returns a new instance of Process.
7 8 9 10 11 |
# File 'lib/foruiman/process.rb', line 7 def initialize(command, = {}) @command = command.dup.freeze @env = ([:env] || ENV.to_h).dup.freeze @cwd = File.([:cwd] || Dir.pwd) end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
5 6 7 |
# File 'lib/foruiman/process.rb', line 5 def command @command end |
#cwd ⇒ Object (readonly)
Returns the value of attribute cwd.
5 6 7 |
# File 'lib/foruiman/process.rb', line 5 def cwd @cwd end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/foruiman/process.rb', line 5 def env @env end |
Instance Method Details
#run(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/foruiman/process.rb', line 13 def run( = {}) environment = env.merge(.fetch(:env, {})) redirects = { chdir: cwd, in: .fetch(:input, $stdin), out: .fetch(:output, $stdout), err: .fetch(:error, $stderr), unsetenv_others: true, close_others: true } return spawn_session(environment, redirects) if [:new_session] ::Process.spawn(environment, "/bin/sh", "-c", shell_command, **redirects, pgroup: true) end |