Add #supported? method for libnotify and notify-send

This commit is contained in:
Guillaume Dott 2015-05-22 16:57:01 +02:00
parent 72eefab5f2
commit cd38483ab7
4 changed files with 32 additions and 10 deletions

View File

@ -1 +1,16 @@
begin
require 'libnotify'
rescue LoadError
end
module Capistrano
module Send
module Libnotify
def self.supported?
defined?(Libnotify) && Libnotify::API.instance_methods.include?(:notify_init)
end
end
end
end
load File.expand_path('../../tasks/libnotify.cap', __FILE__)

View File

@ -1 +1,11 @@
module Capistrano
module Send
module NotifySend
def self.supported?
system('notify-send --version >/dev/null 2>&1') != nil
end
end
end
end
load File.expand_path('../../tasks/notify-send.cap', __FILE__)

View File

@ -1,13 +1,8 @@
begin
require 'libnotify'
rescue LoadError
end
namespace :send do
namespace :libnotify do
desc "Display a notification using libnotify"
task :notify do
if defined?(Libnotify)
if Capistrano::Send::Libnotify.supported?
Libnotify.show(
summary: "Deploy successful on #{fetch(:stage)}!",
body: revision_log_message,

View File

@ -2,11 +2,13 @@ namespace :send do
namespace :'notify-send' do
desc "Display a notification using notify-send"
task :notify do
expire_time = 10000
summary = "Deploy successful on #{fetch(:stage)}!"
body = revision_log_message
if Capistrano::Send::NotifySend.supported?
expire_time = 10000
summary = "Deploy successful on #{fetch(:stage)}!"
body = revision_log_message
`notify-send --expire-time=#{expire_time} '#{summary}' '#{body}'`
`notify-send --expire-time=#{expire_time} '#{summary}' '#{body}'`
end
end
end
end