Class: DispatchRider::Publisher::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dispatch-rider/publisher/base.rb

Overview

Main template for a dispatch rider publisher.

Class Method Summary collapse

Instance Method Summary collapse

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_publisherDispatchRider::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

Parameters:

  • destinations (Array<Symbol>, Symbol)


15
16
17
# File 'lib/dispatch-rider/publisher/base.rb', line 15

def destinations(destinations)
  @destinations = Array(destinations)
end

.publish(*args, &block) ⇒ Object

Raises:

  • (NotImplementedError)


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

Parameters:

  • subject (Symbol)


10
11
12
# File 'lib/dispatch-rider/publisher/base.rb', line 10

def subject(subject)
  @subject = subject
end

Instance Method Details

#publish(body) ⇒ Object

Parameters:

  • body (Hash)


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

Parameters:

  • body (Hash)
  • at (Time)


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