module ActsAsNotifier

Allows an ActiveRecord model to tie notification emails to create and save callbacks with conditions

Usage:

acts_as_notifier do
  after_create/save/update do
    notify recipients, options
  end
end

Params:

recipients  - can be a string containing email addresses, any object with an 'email' method, an array of
              strings/objects, or a proc or symbolic method name returning any of the above. procs will be
              passed the options hash as a parameter.

options
  :if       - string to eval, proc, or method name, !!result must equal true for notification to be sent. procs will
              be passed the options hash as a parameter.
  :mailer   - Typically a class inheriting from ActionMailer::Base.
              May be any class or object with a method accepting a recipients string and instance of model that triggered the notification.
              May also be a string or symbol that evals to a class or object.
  :method   - mailer class method to invoke, should accept recipient list and sending ActiveRecord model as params
  custom    - any additional options can be saved in the action and will be available to procs

Examples:

acts_as_notifier do
  after_create do
    notify proc { User.where(wants_alerts: true) }, :if => proc { send_alert? }, :mailer => MyMailer, :method => :new_widget_alert
  end
  after_save do
    notify :owner, :if => ->widget{ widget.broken? }, :mailer => MyMailer, :method => :broken_widget_alert
  end
end

Configuration:

ActsAsNotifier::Config.use_delayed_job = true/false
ActsAsNotifier::Config.default_mailer  = a class inheriting from ActionMailer::Base
ActsAsNotifier::Config.default_method  = mailer class method to invoke, should accept recipient list and sending
                                         ActiveRecord model as params
ActsAsNotifier::Config.disabled        = true/false, can be globally enabled or disabled at any time

Constants

VERSION