module Guard::Tap::Runner

Public Class Methods

notify(log_level, message, args = { }) click to toggle source
# File lib/guard/tap/runner.rb, line 49
def notify log_level, message, args = { }
  ::Guard::Compat::UI.send log_level, message
  ::Guard::Notifier.notify message, args
end
notify_error(message) click to toggle source
# File lib/guard/tap/runner.rb, line 58
def notify_error message
  notify :error, message, image: :failed
end
notify_success(message) click to toggle source
# File lib/guard/tap/runner.rb, line 54
def notify_success message
  notify :info, message, image: :success
end
run(command, title = command) click to toggle source
# 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
      ::Guard::Compat::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