Class: Shred::Commands::ShellCommand::CommandLine
- Inherits:
-
Object
- Object
- Shred::Commands::ShellCommand::CommandLine
- Defined in:
- lib/shred/commands/base.rb
Instance Attribute Summary collapse
-
#command_line ⇒ Object
readonly
Returns the value of attribute command_line.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
Instance Method Summary collapse
-
#initialize(command_line: nil, out: nil) ⇒ CommandLine
constructor
A new instance of CommandLine.
- #run ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(command_line: nil, out: nil) ⇒ CommandLine
Returns a new instance of CommandLine.
11 12 13 14 |
# File 'lib/shred/commands/base.rb', line 11 def initialize(command_line: nil, out: nil) @command_line = command_line @out = out end |
Instance Attribute Details
#command_line ⇒ Object (readonly)
Returns the value of attribute command_line.
9 10 11 |
# File 'lib/shred/commands/base.rb', line 9 def command_line @command_line end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
9 10 11 |
# File 'lib/shred/commands/base.rb', line 9 def out @out end |
Instance Method Details
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/shred/commands/base.rb', line 16 def run Bundler.with_clean_env do if out Open3.popen3(command_line) do |stdin, stdout, stderr, wait_thr| install_signal_handler(wait_thr.pid) while out_line = stdout.gets out.write(out_line) end while err_line = stderr.gets puts err_line end wait_thr.value end else pid = Process.spawn(command_line) install_signal_handler(pid) Process.wait(pid) $? end end end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/shred/commands/base.rb', line 41 def to_s command_line.to_s end |