Class: Noticed::DeliveryMethods::Base
- Inherits:
-
Object
- Object
- Noticed::DeliveryMethods::Base
- Extended by:
- ActiveModel::Callbacks
- Defined in:
- lib/noticed/delivery_methods/base.rb
Direct Known Subclasses
ActionCable, Database, Email, MicrosoftTeams, Slack, Test, Twilio, Vonage
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#notification ⇒ Object
readonly
Returns the value of attribute notification.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#recipient ⇒ Object
readonly
Returns the value of attribute recipient.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Class Method Summary collapse
-
.inherited(base) ⇒ Object
Copy option names from parent.
- .options(*names) ⇒ Object (also: option)
- .validate!(delivery_method_options) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/noticed/delivery_methods/base.rb', line 9 def logger @logger end |
#notification ⇒ Object (readonly)
Returns the value of attribute notification.
9 10 11 |
# File 'lib/noticed/delivery_methods/base.rb', line 9 def notification @notification end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/noticed/delivery_methods/base.rb', line 9 def @options end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/noticed/delivery_methods/base.rb', line 9 def params @params end |
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
9 10 11 |
# File 'lib/noticed/delivery_methods/base.rb', line 9 def recipient @recipient end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
9 10 11 |
# File 'lib/noticed/delivery_methods/base.rb', line 9 def record @record end |
Class Method Details
.inherited(base) ⇒ Object
Copy option names from parent
13 14 15 16 |
# File 'lib/noticed/delivery_methods/base.rb', line 13 def inherited(base) # :nodoc: base.option_names = option_names.dup super end |
.options(*names) ⇒ Object Also known as: option
18 19 20 |
# File 'lib/noticed/delivery_methods/base.rb', line 18 def (*names) option_names.concat Array.wrap(names) end |
.validate!(delivery_method_options) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/noticed/delivery_methods/base.rb', line 23 def validate!() option_names.each do |option_name| unless .key? option_name raise ValidationError, "option `#{option_name}` must be set for #{name}" end end end |
Instance Method Details
#assign_args(args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/noticed/delivery_methods/base.rb', line 32 def assign_args(args) @notification = args.fetch(:notification_class).constantize.new(args[:params]) @options = args[:options] || {} @params = args[:params] @recipient = args[:recipient] @record = args[:record] # Set the default logger @logger = @options.fetch(:logger, Rails.logger) # Make notification aware of database record and recipient during delivery @notification.record = args[:record] @notification.recipient = args[:recipient] self end |
#deliver ⇒ Object
59 60 61 |
# File 'lib/noticed/delivery_methods/base.rb', line 59 def deliver raise NotImplementedError, "Delivery methods must implement a deliver method" end |
#perform(args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/noticed/delivery_methods/base.rb', line 48 def perform(args) assign_args(args) return if (condition = @options[:if]) && !@notification.send(condition) return if (condition = @options[:unless]) && @notification.send(condition) run_callbacks :deliver do deliver end end |