Class: DispatchRider::Publisher::Base
- Inherits:
-
Object
- Object
- DispatchRider::Publisher::Base
- Defined in:
- lib/dispatch-rider/publisher/base.rb
Class Method Summary collapse
- .default_publisher ⇒ Object
- .destinations(destinations) ⇒ Object
- .publish(*args, &block) ⇒ Object
- .subject(subject) ⇒ Object
Instance Method Summary collapse
- #destinations ⇒ Object
-
#initialize(publisher = nil) ⇒ Base
constructor
A new instance of Base.
- #publish(body) ⇒ Object
- #publisher ⇒ Object
- #subject ⇒ Object
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_publisher ⇒ Object
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
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
#destinations ⇒ Object
52 53 54 |
# File 'lib/dispatch-rider/publisher/base.rb', line 52 def destinations self.class.instance_variable_get(:@destinations) end |
#publish(body) ⇒ Object
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' => , }) publisher.publish(destinations: destinations, message: { subject: subject, body: body }) end |
#publisher ⇒ Object
48 49 50 |
# File 'lib/dispatch-rider/publisher/base.rb', line 48 def publisher @publisher || self.class.default_publisher end |
#subject ⇒ Object
56 57 58 |
# File 'lib/dispatch-rider/publisher/base.rb', line 56 def subject self.class.instance_variable_get(:@subject) end |