Class: DispatchRider::Publisher::Base

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(publisher = nil) ⇒ Base

Returns a new instance of Base.



36
37
38
# File 'lib/dispatch-rider/publisher/base.rb', line 36

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

Class Method Details

.default_publisherObject



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

def default_publisher
  @@default_publisher ||= DispatchRider::Publisher.new
end

.destinations(destinations) ⇒ Object



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

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

.publish(*args, &block) ⇒ Object

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/dispatch-rider/publisher/base.rb', line 20

def publish(*args, &block)
  raise NotImplementedError
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

#destinationsObject



52
53
54
# File 'lib/dispatch-rider/publisher/base.rb', line 52

def destinations
  self.class.instance_variable_get(:@destinations)
end

#publish(body) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
# File 'lib/dispatch-rider/publisher/base.rb', line 40

def publish(body)
  raise ArgumentError, 'body should be a hash' unless body.kind_of?(Hash)
  body = body.merge({
    'guid' => generate_new_message_id,
  })
  publisher.publish(destinations: destinations, message: { subject: subject, body: body })
end

#publisherObject



48
49
50
# File 'lib/dispatch-rider/publisher/base.rb', line 48

def publisher
  @publisher || self.class.default_publisher
end

#subjectObject



56
57
58
# File 'lib/dispatch-rider/publisher/base.rb', line 56

def subject
  self.class.instance_variable_get(:@subject)
end