class Rerun::Notification

Attributes

body[R]
options[R]
title[R]

Public Class Methods

new(title, body, options = Options::DEFAULTS.dup) click to toggle source
# File lib/rerun/notification.rb, line 9
def initialize(title, body, options = Options::DEFAULTS.dup)
  @title = title
  @body = body
  @options = options
end

Public Instance Methods

app_name() click to toggle source
# File lib/rerun/notification.rb, line 50
def app_name
  options[:name]
end
command() click to toggle source
# File lib/rerun/notification.rb, line 15
def command
  return unless mac?

  # todo: strategy or subclass

  s = nil

  if options[:notify] == true or options[:notify] == "growl"
    if (cmd = command_named("growlnotify"))
      # todo: check version of growlnotify and warn if it's too old
      icon_str = ("--image \"#{icon}\"" if icon)
      s = "#{cmd} -n \"#{app_name}\" -m \"#{body}\" \"#{app_name} #{title}\" #{icon_str}"
    end
  end

  if s.nil? and options[:notify] == true or options[:notify] == "osx"
    if (cmd = command_named("terminal-notifier"))
      icon_str = ("-appIcon \"#{icon}\"" if icon)
      s = "#{cmd} -title \"#{app_name}\" -message \"#{body}\" \"#{app_name} #{title}\" #{icon_str}"
    end
  end

  s
end
command_named(name) click to toggle source
# File lib/rerun/notification.rb, line 40
def command_named(name)
  path = `which #{name}`.chomp
  path.empty? ? nil : path
end
icon() click to toggle source
# File lib/rerun/notification.rb, line 54
def icon
  "#{icon_dir}/rails_red_sml.png" if rails?
end
icon_dir() click to toggle source
# File lib/rerun/notification.rb, line 58
def icon_dir
  here = File.expand_path(File.dirname(__FILE__))
  File.expand_path("#{here}/../../icons")
end
send(background = true) click to toggle source
# File lib/rerun/notification.rb, line 45
def send(background = true)
  return unless command
  `#{command}#{" &" if background}`
end