Class: Noticed::DeliveryMethod
- Inherits:
-
Object
- Object
- Noticed::DeliveryMethod
- Extended by:
- ActiveModel::Callbacks
- Includes:
- ApiClient, RequiredOptions
- Defined in:
- lib/noticed/delivery_method.rb
Direct Known Subclasses
Noticed::DeliveryMethods::ActionCable, Noticed::DeliveryMethods::Email, Noticed::DeliveryMethods::Fcm, Noticed::DeliveryMethods::Ios, Noticed::DeliveryMethods::MicrosoftTeams, Noticed::DeliveryMethods::Slack, Noticed::DeliveryMethods::Test, Noticed::DeliveryMethods::TwilioMessaging, Noticed::DeliveryMethods::VonageSms, Noticed::DeliveryMethods::Webhook
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#notification ⇒ Object
readonly
Returns the value of attribute notification.
Instance Method Summary collapse
- #deliver ⇒ Object
- #evaluate_option(name) ⇒ Object
- #fetch_constant(name) ⇒ Object
- #perform(delivery_method_name, notification, recipient: nil, params: {}, overrides: {}) ⇒ Object
Methods included from ApiClient
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/noticed/delivery_method.rb', line 11 def config @config end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
11 12 13 |
# File 'lib/noticed/delivery_method.rb', line 11 def event @event end |
#notification ⇒ Object (readonly)
Returns the value of attribute notification.
11 12 13 |
# File 'lib/noticed/delivery_method.rb', line 11 def notification @notification end |
Instance Method Details
#deliver ⇒ Object
36 37 38 |
# File 'lib/noticed/delivery_method.rb', line 36 def deliver raise NotImplementedError, "Delivery methods must implement the `deliver` method" end |
#evaluate_option(name) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/noticed/delivery_method.rb', line 45 def evaluate_option(name) option = config[name] # Evaluate Proc within the context of the Notification if option&.respond_to?(:call) notification.instance_exec(&option) # Call method if symbol and matching method on Notifier elsif option.is_a?(Symbol) && event.respond_to?(option, true) event.send(option, notification) # Return the value else option end end |
#fetch_constant(name) ⇒ Object
40 41 42 43 |
# File 'lib/noticed/delivery_method.rb', line 40 def fetch_constant(name) option = evaluate_option(name) option.is_a?(String) ? option.constantize : option end |
#perform(delivery_method_name, notification, recipient: nil, params: {}, overrides: {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/noticed/delivery_method.rb', line 15 def perform(delivery_method_name, notification, recipient: nil, params: {}, overrides: {}) # Ephemeral notifications if notification.is_a? String @notification = notification.constantize.new_with_params(recipient, params) @event = @notification.event else @notification = notification @event = notification.event end # Look up config from Notifier and merge overrides @config = event.delivery_methods.fetch(delivery_method_name).config.merge(overrides) return false if config.has_key?(:if) && !evaluate_option(:if) return false if config.has_key?(:unless) && evaluate_option(:unless) run_callbacks :deliver do deliver end end |