Class: FlashFlow::CmdRunner
- Inherits:
-
Object
- Object
- FlashFlow::CmdRunner
- Defined in:
- lib/flash_flow/cmd_runner.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#dry_run ⇒ Object
readonly
Returns the value of attribute dry_run.
-
#last_command ⇒ Object
readonly
Returns the value of attribute last_command.
-
#last_stderr ⇒ Object
readonly
Returns the value of attribute last_stderr.
-
#last_stdout ⇒ Object
readonly
Returns the value of attribute last_stdout.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ CmdRunner
constructor
A new instance of CmdRunner.
- #last_success? ⇒ Boolean
- #run(cmd) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ CmdRunner
Returns a new instance of CmdRunner.
8 9 10 11 12 |
# File 'lib/flash_flow/cmd_runner.rb', line 8 def initialize(opts={}) @dir = opts[:dir] || '.' @dry_run = opts[:dry_run] @logger = opts[:logger] || Logger.new('/dev/null') end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
6 7 8 |
# File 'lib/flash_flow/cmd_runner.rb', line 6 def dir @dir end |
#dry_run ⇒ Object (readonly)
Returns the value of attribute dry_run.
6 7 8 |
# File 'lib/flash_flow/cmd_runner.rb', line 6 def dry_run @dry_run end |
#last_command ⇒ Object (readonly)
Returns the value of attribute last_command.
6 7 8 |
# File 'lib/flash_flow/cmd_runner.rb', line 6 def last_command @last_command end |
#last_stderr ⇒ Object (readonly)
Returns the value of attribute last_stderr.
6 7 8 |
# File 'lib/flash_flow/cmd_runner.rb', line 6 def last_stderr @last_stderr end |
#last_stdout ⇒ Object (readonly)
Returns the value of attribute last_stdout.
6 7 8 |
# File 'lib/flash_flow/cmd_runner.rb', line 6 def last_stdout @last_stdout end |
Instance Method Details
#last_success? ⇒ Boolean
33 34 35 |
# File 'lib/flash_flow/cmd_runner.rb', line 33 def last_success? @success end |
#run(cmd) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/flash_flow/cmd_runner.rb', line 14 def run(cmd) @last_command = cmd if dry_run puts "#{dir}$ #{cmd}" '' else Dir.chdir(dir) do Open3.popen3(cmd) do |_, stdout, stderr, wait_thr| @last_stdout = stdout.read @last_stderr = stderr.read @success = wait_thr.value.success? end end @logger.debug("#{dir}$ #{cmd}") last_stdout.split("\n").each { |line| @logger.debug(line) } last_stderr.split("\n").each { |line| @logger.debug(line) } end end |