class ActiveNotifier::Base

Attributes

configurations[RW]
locale_attribute[RW]
channels[RW]
recipient[RW]

Public Class Methods

deliver_now(attributes) click to toggle source
# File lib/active_notifier/base.rb, line 34
def deliver_now(attributes)
  new(attributes).deliver_now
end
deliver_through(channel, &blk) click to toggle source
# File lib/active_notifier/base.rb, line 38
def deliver_through(channel, &blk)
  self.configurations ||= {}
  config = Configuration.new.tap(&blk)
  configurations[channel] = config
end
locale_for(recipient) click to toggle source
# File lib/active_notifier/base.rb, line 44
def locale_for(recipient)
  recipient.public_send(locale_attribute)
rescue
  I18n.default_locale
end
new(attributes={}) click to toggle source
# File lib/active_notifier/base.rb, line 5
def initialize(attributes={})
  attributes.each do |(key, value)|
    self.public_send("#{key}=", value)
  end
end

Public Instance Methods

deliver_now() click to toggle source
# File lib/active_notifier/base.rb, line 13
def deliver_now
  delivered = false
  locale = self.class.locale_for(recipient)
  I18n.with_locale(locale) do
    until channels.empty? || delivered
      channel = channels.shift
      begin
        deliverable(channel).deliver_now
        delivered = true
      rescue ActiveNotifier::DeliveryImpossible => e
        delivered = false
        msg = "Unable to deliver to channel #{channel}: #{e.message}"
        ActiveNotifier.logger && ActiveNotifier.logger.warn(msg)
      end
    end
  end
end

Private Instance Methods

deliverable(channel) click to toggle source
# File lib/active_notifier/base.rb, line 53
def deliverable(channel)
  configuration = self.class.configurations[channel]
  transport = ActiveNotifier::Transports.for(channel, configuration, self)
  transport.deliverable(self)
end