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.



27
28
29
# File 'lib/dispatch-rider/publisher/base.rb', line 27

def initialize(publisher = nil)
  @publisher = publisher
end

Class Method Details

.default_publisherDispatchRider::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

Parameters:

  • destinations (Array<Symbol>, Symbol)


13
14
15
# File 'lib/dispatch-rider/publisher/base.rb', line 13

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

.publish(*args, &block) ⇒ Object

Raises:

  • (NotImplementedError)


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

Parameters:

  • subject (Symbol)


8
9
10
# File 'lib/dispatch-rider/publisher/base.rb', line 8

def subject(subject)
  @subject = subject
end

Instance Method Details

#publish(body) ⇒ Object

Parameters:

  • body (Hash)


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

Parameters:

  • body (Hash)
  • at (Time)


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