Class: DispatchRider::Publisher::Base
- Inherits:
-
Object
- Object
- DispatchRider::Publisher::Base
- Defined in:
- lib/dispatch-rider/publisher/base.rb
Overview
Main template for a dispatch rider publisher.
Class Method Summary collapse
- .default_publisher ⇒ DispatchRider::Publisher
- .destinations(destinations) ⇒ Object
- .publish(*args, &block) ⇒ Object
- .subject(subject) ⇒ Object
Instance Method Summary collapse
-
#initialize(publisher = nil) ⇒ Base
constructor
A new instance of Base.
- #publish(body) ⇒ Object
- #publish_later(body, at:) ⇒ Object
Constructor Details
#initialize(publisher = nil) ⇒ Base
Returns a new instance of Base.
29 30 31 |
# File 'lib/dispatch-rider/publisher/base.rb', line 29 def initialize(publisher = nil) @publisher = publisher end |
Class Method Details
.default_publisher ⇒ DispatchRider::Publisher
20 21 22 |
# File 'lib/dispatch-rider/publisher/base.rb', line 20 def default_publisher @@default_publisher ||= DispatchRider::Publisher.new end |
.destinations(destinations) ⇒ Object
15 16 17 |
# File 'lib/dispatch-rider/publisher/base.rb', line 15 def destinations(destinations) @destinations = Array(destinations) end |
.publish(*args, &block) ⇒ Object
24 25 26 |
# 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) ⇒ Object
10 11 12 |
# File 'lib/dispatch-rider/publisher/base.rb', line 10 def subject(subject) @subject = subject end |
Instance Method Details
#publish(body) ⇒ Object
34 35 36 37 |
# 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:) ⇒ Object
41 42 43 44 45 46 |
# 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 |