From 9b8228e7916180ebed861891c9266127a6e25324 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Sun, 5 Apr 2015 22:45:31 -0300 Subject: [PATCH] rails4: use ApplicationMailer pattern --- app/mailers/application_mailer.rb | 12 ++++++++++++ app/mailers/comment_notifier.rb | 2 +- app/mailers/contact.rb | 2 +- app/mailers/mailing.rb | 2 +- app/mailers/pending_task_notifier.rb | 2 +- app/mailers/scrap_notifier.rb | 2 +- app/mailers/task_mailer.rb | 2 +- app/mailers/user_mailer.rb | 2 +- lib/noosfero/mailer.rb | 13 ------------- lib/noosfero/plugin/mailer_base.rb | 4 +++- plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb | 2 +- 11 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 app/mailers/application_mailer.rb delete mode 100644 lib/noosfero/mailer.rb diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..11acb50 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,12 @@ +class ApplicationMailer < ActionMailer::Base + + attr_accessor :environment + + def default_url_options options = nil + options ||= {} + options[:host] = environment.default_hostname if environment + options + end + +end + diff --git a/app/mailers/comment_notifier.rb b/app/mailers/comment_notifier.rb index 7dacb2f..1ba1be0 100644 --- a/app/mailers/comment_notifier.rb +++ b/app/mailers/comment_notifier.rb @@ -1,4 +1,4 @@ -class CommentNotifier < Noosfero::Mailer +class CommentNotifier < ApplicationMailer def notification(comment) profile = comment.article.profile diff --git a/app/mailers/contact.rb b/app/mailers/contact.rb index cf11cd1..f3dc426 100644 --- a/app/mailers/contact.rb +++ b/app/mailers/contact.rb @@ -30,7 +30,7 @@ class Contact Contact::Sender.notification(self).deliver end - class Sender < Noosfero::Mailer + class Sender < ApplicationMailer def notification(contact) self.environment = contact.dest.environment diff --git a/app/mailers/mailing.rb b/app/mailers/mailing.rb index f50cc42..c98595f 100644 --- a/app/mailers/mailing.rb +++ b/app/mailers/mailing.rb @@ -48,7 +48,7 @@ class Mailing < ActiveRecord::Base end end - class Sender < Noosfero::Mailer + class Sender < ApplicationMailer def notification(mailing, recipient) @message = mailing.body diff --git a/app/mailers/pending_task_notifier.rb b/app/mailers/pending_task_notifier.rb index 90ab6c5..4fd637b 100644 --- a/app/mailers/pending_task_notifier.rb +++ b/app/mailers/pending_task_notifier.rb @@ -1,4 +1,4 @@ -class PendingTaskNotifier < Noosfero::Mailer +class PendingTaskNotifier < ApplicationMailer def notification(person) self.environment = person.environment diff --git a/app/mailers/scrap_notifier.rb b/app/mailers/scrap_notifier.rb index ff152e6..1daa35a 100644 --- a/app/mailers/scrap_notifier.rb +++ b/app/mailers/scrap_notifier.rb @@ -1,4 +1,4 @@ -class ScrapNotifier < Noosfero::Mailer +class ScrapNotifier < ApplicationMailer def notification(scrap) sender, receiver = scrap.sender, scrap.receiver diff --git a/app/mailers/task_mailer.rb b/app/mailers/task_mailer.rb index a8c1684..b2fa21c 100644 --- a/app/mailers/task_mailer.rb +++ b/app/mailers/task_mailer.rb @@ -1,4 +1,4 @@ -class TaskMailer < Noosfero::Mailer +class TaskMailer < ApplicationMailer def target_notification(task, message) self.environment = task.environment diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 8556356..6b9549f 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,4 +1,4 @@ -class UserMailer < Noosfero::Mailer +class UserMailer < ApplicationMailer def activation_email_notify(user) self.environment = user.environment diff --git a/lib/noosfero/mailer.rb b/lib/noosfero/mailer.rb deleted file mode 100644 index acddce3..0000000 --- a/lib/noosfero/mailer.rb +++ /dev/null @@ -1,13 +0,0 @@ - -class Noosfero::Mailer < ActionMailer::Base - - attr_accessor :environment - - def default_url_options options = nil - options ||= {} - options[:host] = environment.default_hostname if environment - options - end - -end - diff --git a/lib/noosfero/plugin/mailer_base.rb b/lib/noosfero/plugin/mailer_base.rb index a5eb422..a5539e6 100644 --- a/lib/noosfero/plugin/mailer_base.rb +++ b/lib/noosfero/plugin/mailer_base.rb @@ -1,4 +1,6 @@ -class Noosfero::Plugin::MailerBase < ActionMailer::Base +require_relative '../../../app/mailers/application_mailer' + +class Noosfero::Plugin::MailerBase < ApplicationMailer def self.plugin_name name.split('::').first.gsub(/Plugin$/, '').underscore diff --git a/plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb b/plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb index d2e02c8..7f8bb9e 100644 --- a/plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb +++ b/plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb @@ -28,7 +28,7 @@ class WorkAssignmentPlugin::EmailContact WorkAssignmentPlugin::EmailContact::EmailSender.notification(self).deliver end - class EmailSender < Noosfero::Mailer + class EmailSender < ApplicationMailer def notification(email_contact) self.environment = email_contact.sender.environment -- libgit2 0.21.2