Class: Airake::Runner
Overview
Runs commands
Instance Attribute Summary collapse
- #cmd ⇒ Object readonly
- #output ⇒ Object readonly
- #process ⇒ Object readonly
- #took ⇒ Object readonly
Class Method Summary collapse
-
.run(command, method, *args) ⇒ Object
Run airake command.
Instance Method Summary collapse
- #exit_code ⇒ Object
- #fail ⇒ Object
-
#initialize(cmd) ⇒ Runner
constructor
A new instance of Runner.
- #pid ⇒ Object
- #run(verbose = true) ⇒ Object
- #run? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(cmd) ⇒ Runner
Returns a new instance of Runner.
9 10 11 |
# File 'lib/airake/runner.rb', line 9 def initialize(cmd) @cmd = RUBY_PLATFORM =~ /win32/ ? "cmd.exe /c #{cmd} 2>&1" : "#{cmd} 2>&1" end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
7 8 9 |
# File 'lib/airake/runner.rb', line 7 def cmd @cmd end |
#output ⇒ Object (readonly)
7 8 9 |
# File 'lib/airake/runner.rb', line 7 def output @output end |
#process ⇒ Object (readonly)
7 8 9 |
# File 'lib/airake/runner.rb', line 7 def process @process end |
#took ⇒ Object (readonly)
7 8 9 |
# File 'lib/airake/runner.rb', line 7 def took @took end |
Class Method Details
.run(command, method, *args) ⇒ Object
Run airake command
59 60 61 62 |
# File 'lib/airake/runner.rb', line 59 def self.run(command, method, *args) runner = self.new(command.send(method, *args)) runner.run end |
Instance Method Details
#exit_code ⇒ Object
46 47 48 |
# File 'lib/airake/runner.rb', line 46 def exit_code @process ? @process.exitstatus : nil end |
#fail ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/airake/runner.rb', line 33 def fail raise <<-EOS [exited=#{exit_code}, pid=#{pid}] failed: #{cmd} EOS end |
#pid ⇒ Object
50 51 52 |
# File 'lib/airake/runner.rb', line 50 def pid @process ? @process.pid : nil end |
#run(verbose = true) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/airake/runner.rb', line 13 def run(verbose = true) puts "Running: #{@cmd}" if verbose t1 = Time.now IO.popen(@cmd) do |f| while s = f.read(1) printf s STDOUT.flush end end @process = $? @took = Time.now - t1 if verbose success? or fail #puts "Took %.2fs" % [ @took ] end end |
#run? ⇒ Boolean
42 43 44 |
# File 'lib/airake/runner.rb', line 42 def run? !@process.nil? end |
#success? ⇒ Boolean
54 55 56 |
# File 'lib/airake/runner.rb', line 54 def success? return run? && @process.success? end |