Module: Feste::Mailer::ClassMethods

Defined in:
lib/feste/mailer.rb

Instance Method Summary collapse

Instance Method Details

#action_methodsObject



119
120
121
122
123
124
# File 'lib/feste/mailer.rb', line 119

def action_methods
  feste_methods = %w[
    action_categories action_categories= action_categories?
  ]
  Set.new(super - feste_methods)
end

#categorize(meths = [], as:) ⇒ Object

Assign action(s) to a category The actions in the mailer that are included in the given category can be limited by listing them in an array of symbols.

class ReminderMailer < ActionMailer::Base

  categorize [:send_reminder, :send_update], as: :reminder_emails

  def send_reminder(user)
    ...
  end

  def send_update(user)
    ...
  end

  def send_alert(user)
    ...
  end
end

ReminderMailer.action_categories => {
  send_reminder: :reminder_emails,
  send_update: :reminder_emails
}

If no array is provided, all actions in the mailer will be categorized.

class ReminderMailer < ActionMailer::Base

  categorize as: :reminder_emails

  def send_reminder(user)
    ...
  end

  def send_update(user)
    ...
  end

  def send_alert(user)
    ...
  end
end

ReminderMailer.action_categories => { all: :reminder_emails }

Parameters:

  • (Array, Symbol)


114
115
116
117
# File 'lib/feste/mailer.rb', line 114

def categorize(meths = [], as:)
  actions = meths.empty? ? [:all] : meths
  actions.each { |action| self.action_categories[action.to_sym] = as }
end