class DispatchRider::Publisher::Base
Main template for a dispatch rider publisher.
Public Class Methods
default_publisher()
click to toggle source
@return [DispatchRider::Publisher]
# File lib/dispatch-rider/publisher/base.rb, line 20 def default_publisher @@default_publisher ||= DispatchRider::Publisher.new end
destinations(destinations)
click to toggle source
@param [Array<Symbol>, Symbol] destinations
# File lib/dispatch-rider/publisher/base.rb, line 15 def destinations(destinations) @destinations = Array(destinations) end
new(publisher = nil)
click to toggle source
# File lib/dispatch-rider/publisher/base.rb, line 29 def initialize(publisher = nil) @publisher = publisher end
publish(*args, &block)
click to toggle source
# File lib/dispatch-rider/publisher/base.rb, line 24 def publish(*args, &block) raise NotImplementedError, "subclass of DispatchRider::Publisher::Base must implement .publish" end
subject(subject)
click to toggle source
@param [Symbol] subject
# File lib/dispatch-rider/publisher/base.rb, line 10 def subject(subject) @subject = subject end
Public Instance Methods
publish(body)
click to toggle source
@param [Hash] body
# File lib/dispatch-rider/publisher/base.rb, line 34 def publish(body) validate_body(body) publisher.publish(destinations: destinations, message: { subject: subject, body: body }) end
publish_later(body, at:)
click to toggle source
@param [Hash] body @param [Time] at
# File lib/dispatch-rider/publisher/base.rb, line 41 def publish_later(body, at:) validate_body(body) DispatchRider::ScheduledJob.create! scheduled_at: at, destinations: destinations, message: { subject: subject, body: body } end
Private Instance Methods
destinations()
click to toggle source
# File lib/dispatch-rider/publisher/base.rb, line 54 def destinations self.class.instance_variable_get(:@destinations) end
publisher()
click to toggle source
# File lib/dispatch-rider/publisher/base.rb, line 50 def publisher @publisher || self.class.default_publisher end
subject()
click to toggle source
# File lib/dispatch-rider/publisher/base.rb, line 58 def subject self.class.instance_variable_get(:@subject) end
validate_body(body)
click to toggle source
# File lib/dispatch-rider/publisher/base.rb, line 62 def validate_body(body) raise ArgumentError, 'body should be a hash' unless body.is_a?(Hash) end