Class: FlashFlow::CmdRunner
- Inherits:
-
Object
- Object
- FlashFlow::CmdRunner
- Defined in:
- lib/flash_flow/cmd_runner.rb
Constant Summary collapse
- LOG_NONE =
:log_none
- LOG_CMD =
:log_cmd
Instance Attribute Summary collapse
-
#dir ⇒ Object
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, opts = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ CmdRunner
Returns a new instance of CmdRunner.
12 13 14 15 16 |
# File 'lib/flash_flow/cmd_runner.rb', line 12 def initialize(opts={}) @dir = opts[:dir] || `pwd`.strip @dry_run = opts[:dry_run] @logger = opts[:logger] || Logger.new('/dev/null') end |
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
10 11 12 |
# File 'lib/flash_flow/cmd_runner.rb', line 10 def dir @dir end |
#dry_run ⇒ Object (readonly)
Returns the value of attribute dry_run.
9 10 11 |
# File 'lib/flash_flow/cmd_runner.rb', line 9 def dry_run @dry_run end |
#last_command ⇒ Object (readonly)
Returns the value of attribute last_command.
9 10 11 |
# File 'lib/flash_flow/cmd_runner.rb', line 9 def last_command @last_command end |
#last_stderr ⇒ Object (readonly)
Returns the value of attribute last_stderr.
9 10 11 |
# File 'lib/flash_flow/cmd_runner.rb', line 9 def last_stderr @last_stderr end |
#last_stdout ⇒ Object (readonly)
Returns the value of attribute last_stdout.
9 10 11 |
# File 'lib/flash_flow/cmd_runner.rb', line 9 def last_stdout @last_stdout end |
Instance Method Details
#last_success? ⇒ Boolean
35 36 37 |
# File 'lib/flash_flow/cmd_runner.rb', line 35 def last_success? @success end |
#run(cmd, opts = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/flash_flow/cmd_runner.rb', line 18 def run(cmd, opts={}) @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 log(cmd, opts[:log]) end end |