Skip to content

Commit

Permalink
Attempt to fix issue Codaisseur#19 by using the binary from $PATH.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wouter de Vos committed Nov 2, 2014
1 parent 31114e3 commit 3eec505
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
20 changes: 17 additions & 3 deletions lib/terminal-notifier-guard.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
module TerminalNotifier
module Guard
VERSION = "1.6.2"
BIN_PATH = "/usr/local/Cellar/terminal-notifier/1.6.1/terminal-notifier.app/Contents/MacOS/terminal-notifier"
ICONS_PATH = File.expand_path("../../icons", __FILE__)
GUARD_ICON = File.join(ICONS_PATH, 'guard.png')

def self.osx_version
Gem::Version.new(`sw_vers -productVersion`.strip)
end

def self.terminal_notifier_version
return unless installed?
Gem::Version.new(`#{bin_path}`.lines.first.match(/\d\.\d\.\d/)[0])
rescue
Gem::Version.new("0.0.0")
end

def self.deprecation_check
if osx_version <= Gem::Version.new('10.8')
raise "OSX 10.8 is no longer supported by this gem. Please revert to version <= 1.5.3."
end

if terminal_notifier_version < Gem::Version.new('1.6.0')
puts "Notice: Your terminal-notifier is older than what terminal-notifier-guard supports, consider upgrading."
end
end

# Returns wether or not the current platform is Mac OS X 10.8, or higher.
Expand All @@ -27,14 +37,18 @@ def self.available?

# Whether or not the terminal notifier is installed
def self.installed?
return true if File.exist? BIN_PATH
File.exist? bin_path
end

def self.bin_path
@@binary ||= `which terminal-notifier`.chomp
end

def self.execute(verbose, options)
if available? && installed?
options.merge!({ :appIcon => GUARD_ICON, :contentImage => icon(options.delete(:type)) })

command = [BIN_PATH, *options.map { |k,v| ["-#{k}", v.to_s] }.flatten]
command = [bin_path, *options.map { |k,v| ["-#{k}", v.to_s] }.flatten]
if RUBY_VERSION < '1.9'
require 'shellwords'
command = Shellwords.shelljoin(command)
Expand Down
12 changes: 6 additions & 6 deletions spec/terminal-notifier-guard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
describe "TerminalNotifier::Guard" do
describe ".execute" do
it "executes the tool with the given options" do
command = [TerminalNotifier::Guard::BIN_PATH, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon]
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon]
if RUBY_VERSION < '1.9'
require 'shellwords'
command = Shellwords.shelljoin(command)
Expand All @@ -21,7 +21,7 @@
end

it "executes with the right icon path according to the type option" do
command = [TerminalNotifier::Guard::BIN_PATH, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:success)]
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:success)]
if RUBY_VERSION < '1.9'
require 'shellwords'
command = Shellwords.shelljoin(command)
Expand All @@ -31,7 +31,7 @@
end

it "returns the result output of the command" do
TerminalNotifier::Guard.execute(false, 'help' => '').should == `'#{TerminalNotifier::Guard::BIN_PATH}' -help`
TerminalNotifier::Guard.execute(false, 'help' => '').should == `'#{TerminalNotifier::Guard.bin_path}' -help`
end

it "sends a notification" do
Expand Down Expand Up @@ -87,7 +87,7 @@

describe ".failed" do
it "executes with the 'failed' icon flag" do
command = [TerminalNotifier::Guard::BIN_PATH, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:failed)]
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:failed)]
if RUBY_VERSION < '1.9'
require 'shellwords'
command = Shellwords.shelljoin(command)
Expand All @@ -99,7 +99,7 @@

describe ".success" do
it "executes with the 'success' icon flag" do
command = [TerminalNotifier::Guard::BIN_PATH, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:success)]
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:success)]
if RUBY_VERSION < '1.9'
require 'shellwords'
command = Shellwords.shelljoin(command)
Expand All @@ -111,7 +111,7 @@

describe ".pending" do
it "executes with the 'pending' icon flag" do
command = [TerminalNotifier::Guard::BIN_PATH, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:pending)]
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:pending)]
if RUBY_VERSION < '1.9'
require 'shellwords'
command = Shellwords.shelljoin(command)
Expand Down

0 comments on commit 3eec505

Please sign in to comment.