Module: Guard::Tap::Runner

Defined in:
lib/guard/tap/runner.rb

Class Method Summary collapse

Class Method Details

.notify(log_level, message, args = { }) ⇒ Object



49
50
51
52
# File 'lib/guard/tap/runner.rb', line 49

def notify log_level, message, args = { }
  ::Guard::UI.send log_level, message
  ::Guard::Notifier.notify message, args
end

.notify_error(message) ⇒ Object



58
59
60
# File 'lib/guard/tap/runner.rb', line 58

def notify_error message
  notify :error, message, image: :failed
end

.notify_success(message) ⇒ Object



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

def notify_success message
  notify :info, message, image: :success
end

.run(command, title = command) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/guard/tap/runner.rb', line 6

def run command, title = command
  notify :info, "runnning: #{title}"

  now_error = false
  error_message = ''
  flush_error = lambda {
    next unless error_message.length > 0
    notify_error error_message
    error_message = ''
  }

  IO.popen(command, "r+"){ |io|
    while line = io.gets
      UI.debug line
      if line =~ /^ok/
        now_error = false
        flush_error.call
      elsif line =~ /^\d+.{2}\d+$/
        now_error = false
        flush_error.call
      elsif line =~ /^not ok/
        flush_error.call
        now_error = (line =~ / # TODO/ ? false : true)
      end
      if now_error
        error_message << line
      end
    end
  }
  flush_error.call

  if $?.success?
    notify_success "success: #{title}"
  else
    notify_error "failed: #{title}"
  end

  $?.success?
rescue SystemCallError
  notify_error "failed: #{title}"
  false
end