class Guard::SuperShell

Public Instance Methods

name() click to toggle source
# File lib/guard/super_shell.rb, line 26
def name
  options[:name] || "shell"
end
run_all() click to toggle source
# File lib/guard/super_shell.rb, line 22
def run_all
  run_command
end
run_on_changes(files) click to toggle source
# File lib/guard/super_shell.rb, line 17
def run_on_changes(files)
  Compat::UI.info "#{name}: #{files.join}"
  run_command(files)
end
start() click to toggle source
# File lib/guard/super_shell.rb, line 7
def start
  if options[:run_at_start]
    Compat::UI.info "#{name} running at start"
    run_command
  end
end
stop() click to toggle source
# File lib/guard/super_shell.rb, line 14
def stop
end

Private Instance Methods

notify?() click to toggle source
# File lib/guard/super_shell.rb, line 51
def notify?
  options.fetch(:notification, true)
end
run_at_start?() click to toggle source
# File lib/guard/super_shell.rb, line 55
def run_at_start?
  options.fetch(:run_at_start, false)
end
run_command(files = []) click to toggle source
# File lib/guard/super_shell.rb, line 32
def run_command(files = [])
  command = options[:command].call(files)
  (stdin, stdout_and_stderr, thread) = Open3.popen2e(command)
  output = stdout_and_stderr.read
  puts output

  if thread.value.success?
    Compat::UI.notify(output.lines.last, title: name, type: :success) if notify?
  else
    Compat::UI.notify(output.lines.last, title: name, type: :failed) if notify?
    throw :task_has_failed
  end
rescue => e
  msg = "#{e.class.name}: #{e.message}"
  Compat::UI.error "#{name}: raised error #{msg}"
  Compat::UI.notify(msg, title: name, type: :failed) if notify?
  throw :task_has_failed
end