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.
27 28 29 |
# File 'lib/dispatch-rider/publisher/base.rb', line 27 def initialize(publisher = nil) @publisher = publisher end |
Class Method Details
.default_publisher ⇒ DispatchRider::Publisher
18 19 20 |
# File 'lib/dispatch-rider/publisher/base.rb', line 18 def default_publisher @@default_publisher ||= DispatchRider::Publisher.new end |
.destinations(destinations) ⇒ Object
13 14 15 |
# File 'lib/dispatch-rider/publisher/base.rb', line 13 def destinations(destinations) @destinations = Array(destinations) end |
.publish(*args, &block) ⇒ Object
22 23 24 |
# File 'lib/dispatch-rider/publisher/base.rb', line 22 def publish(*args, &block) raise NotImplementedError, "subclass of DispatchRider::Publisher::Base must implement .publish" end |
.subject(subject) ⇒ Object
8 9 10 |
# File 'lib/dispatch-rider/publisher/base.rb', line 8 def subject(subject) @subject = subject end |
Instance Method Details
#publish(body) ⇒ Object
32 33 34 35 |
# File 'lib/dispatch-rider/publisher/base.rb', line 32 def publish(body) validate_body(body) publisher.publish(destinations: destinations, message: { subject: subject, body: body }) end |
#publish_later(body, at:) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/dispatch-rider/publisher/base.rb', line 39 def publish_later(body, at:) validate_body(body) DispatchRider::ScheduledJob.create! scheduled_at: at, destinations: destinations, message: { subject: subject, body: body } end |