Class: Airake::Runner

Inherits:
Object show all
Defined in:
lib/airake/runner.rb

Overview

Runs commands

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#cmdObject (readonly)



7
8
9
# File 'lib/airake/runner.rb', line 7

def cmd
  @cmd
end

#outputObject (readonly)



7
8
9
# File 'lib/airake/runner.rb', line 7

def output
  @output
end

#processObject (readonly)



7
8
9
# File 'lib/airake/runner.rb', line 7

def process
  @process
end

#tookObject (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_codeObject



46
47
48
# File 'lib/airake/runner.rb', line 46

def exit_code
  @process ? @process.exitstatus : nil
end

#failObject



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

#pidObject



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

Returns:

  • (Boolean)


42
43
44
# File 'lib/airake/runner.rb', line 42

def run?
  !@process.nil?
end

#success?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/airake/runner.rb', line 54

def success?
  return run? && @process.success?
end