Rename push to process on PushTarget for clearer semantics
"Push to target" reads naturally - we push the notification to the target. "Target processes" also makes sense - the target receives and handles the notification in its own way. - Add class method PushTarget.process(notification) that instantiates and calls the instance method - Rename instance method from push to process - Add private push_to helper in Pushable for readable iteration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,11 +3,15 @@ class Notification::PushTarget
|
||||
|
||||
delegate :card, to: :notification
|
||||
|
||||
def self.process(notification)
|
||||
new(notification).process
|
||||
end
|
||||
|
||||
def initialize(notification)
|
||||
@notification = notification
|
||||
end
|
||||
|
||||
def push
|
||||
def process
|
||||
return unless should_push?
|
||||
|
||||
perform_push
|
||||
|
||||
@@ -16,9 +16,10 @@ module Notification::Pushable
|
||||
|
||||
private
|
||||
def resolve_push_target(target)
|
||||
if target.is_a?(Notification::PushTarget) then target
|
||||
else
|
||||
if target.is_a?(Symbol)
|
||||
"Notification::PushTarget::#{target.to_s.classify}".constantize
|
||||
else
|
||||
target
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -28,9 +29,7 @@ module Notification::Pushable
|
||||
end
|
||||
|
||||
def push
|
||||
self.class.push_targets.each do |target|
|
||||
target.new(self).push
|
||||
end
|
||||
self.class.push_targets.each { |target| push_to(target) }
|
||||
end
|
||||
|
||||
def pushable?
|
||||
@@ -42,6 +41,10 @@ module Notification::Pushable
|
||||
end
|
||||
|
||||
private
|
||||
def push_to(target)
|
||||
target.process(self)
|
||||
end
|
||||
|
||||
def payload_type
|
||||
source_type.presence_in(%w[ Event Mention ]) || "Default"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user