lib/capistrano/notifier/mail.rb in capistrano-notifier-0.1.2 vs lib/capistrano/notifier/mail.rb in capistrano-notifier-0.2.0

- old
+ new

@@ -1,38 +1,73 @@ require 'capistrano/notifier' -require 'action_mailer' +begin + require 'action_mailer' +rescue LoadError => e + require 'actionmailer' +end + +class Capistrano::Notifier::Mailer < ActionMailer::Base + + if ActionMailer::Base.respond_to?(:mail) + def notice(text, from, subject, to, delivery_method) + mail({ + :body => text, + :delivery_method => delivery_method, + :from => from, + :subject => subject, + :to => to + }) + end + else + def notice(text, from, subject, to) + body text + from from + subject subject + recipients to + end + end + +end + class Capistrano::Notifier::Mail < Capistrano::Notifier::Base def self.load_into(configuration) configuration.load do namespace :deploy do namespace :notify do desc 'Send a deployment notification via email.' task :mail do Capistrano::Notifier::Mail.new(configuration).perform + + if configuration.notifier_mail_options[:method] == :test + puts ActionMailer::Base.deliveries + end end end end after 'deploy:restart', 'deploy:notify:mail' end end def perform - mail = ActionMailer::Base.mail({ - :body => text, - :delivery_method => notify_method, - :from => from, - :subject => subject, - :to => to - }) + if defined?(ActionMailer::Base) && ActionMailer::Base.respond_to?(:mail) + perform_with_action_mailer + else + perform_with_legacy_action_mailer + end + end - mail.deliver + private - puts ActionMailer::Base.deliveries if notify_method == :test + def perform_with_legacy_action_mailer(notifier = Capistrano::Notifier::Mailer) + notifier.delivery_method = notify_method + notifier.deliver_notice(text, from, subject, to) end - private + def perform_with_action_mailer(notifier = Capistrano::Notifier::Mailer) + notifier.notice(text, from, subject, to, notify_method).deliver + end def body <<-BODY.gsub(/^ {6}/, '') #{user_name} deployed #{application.titleize} branch