Class: ActiveNotifier::Base
- Inherits:
-
Object
- Object
- ActiveNotifier::Base
- Defined in:
- lib/active_notifier/base.rb
Defined Under Namespace
Classes: Configuration
Class Attribute Summary collapse
-
.configurations ⇒ Object
Returns the value of attribute configurations.
-
.locale_attribute ⇒ Object
Returns the value of attribute locale_attribute.
Instance Attribute Summary collapse
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#recipient ⇒ Object
Returns the value of attribute recipient.
Class Method Summary collapse
- .deliver_now(attributes) ⇒ Object
- .deliver_through(channel, &blk) ⇒ Object
- .locale_for(recipient) ⇒ Object
Instance Method Summary collapse
- #deliver_now ⇒ Object
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 |
# File 'lib/active_notifier/base.rb', line 5 def initialize(attributes={}) attributes.each do |(key, value)| self.public_send("#{key}=", value) end end |
Class Attribute Details
.configurations ⇒ Object
Returns the value of attribute configurations.
32 33 34 |
# File 'lib/active_notifier/base.rb', line 32 def configurations @configurations end |
.locale_attribute ⇒ Object
Returns the value of attribute locale_attribute.
32 33 34 |
# File 'lib/active_notifier/base.rb', line 32 def locale_attribute @locale_attribute end |
Instance Attribute Details
#channels ⇒ Object
Returns the value of attribute channels.
3 4 5 |
# File 'lib/active_notifier/base.rb', line 3 def channels @channels end |
#recipient ⇒ Object
Returns the value of attribute recipient.
3 4 5 |
# File 'lib/active_notifier/base.rb', line 3 def recipient @recipient end |
Class Method Details
.deliver_now(attributes) ⇒ Object
34 35 36 |
# File 'lib/active_notifier/base.rb', line 34 def deliver_now(attributes) new(attributes).deliver_now end |
.deliver_through(channel, &blk) ⇒ Object
38 39 40 41 42 |
# 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) ⇒ Object
44 45 46 47 48 |
# File 'lib/active_notifier/base.rb', line 44 def locale_for(recipient) recipient.public_send(locale_attribute) rescue I18n.default_locale end |
Instance Method Details
#deliver_now ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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.}" ActiveNotifier.logger && ActiveNotifier.logger.warn(msg) end end end end |