Class: Fare::Publisher
- Inherits:
-
Object
- Object
- Fare::Publisher
- Defined in:
- lib/fare/publisher.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #action ⇒ Object
- #app_name ⇒ Object
- #call ⇒ Object
- #ensure_topic_publishable! ⇒ Object
- #event ⇒ Object
-
#initialize(configuration, options) ⇒ Publisher
constructor
A new instance of Publisher.
- #payload ⇒ Object
- #subject ⇒ Object
- #topic ⇒ Object
- #topic_info ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(configuration, options) ⇒ Publisher
8 9 10 11 |
# File 'lib/fare/publisher.rb', line 8 def initialize(configuration, ) @configuration = configuration = end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/fare/publisher.rb', line 6 def configuration @configuration end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/fare/publisher.rb', line 6 def end |
Instance Method Details
#action ⇒ Object
42 43 44 |
# File 'lib/fare/publisher.rb', line 42 def action .fetch(:action) end |
#app_name ⇒ Object
54 55 56 |
# File 'lib/fare/publisher.rb', line 54 def app_name configuration.app_name end |
#call ⇒ Object
13 14 15 16 |
# File 'lib/fare/publisher.rb', line 13 def call ensure_topic_publishable! topic.publish(event.serialize) end |
#ensure_topic_publishable! ⇒ Object
58 59 60 61 62 |
# File 'lib/fare/publisher.rb', line 58 def ensure_topic_publishable! unless topic_info raise UnknownTopicError, "Topic with subject #{subject} and action #{action} not in lock file, maybe run `fare update`" end end |
#event ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fare/publisher.rb', line 26 def event Event.new( id: "event-#{SecureRandom.uuid}", subject: subject, action: action, payload: payload, source: app_name, version: version, sent_at: Time.now.utc, ) end |
#payload ⇒ Object
46 47 48 |
# File 'lib/fare/publisher.rb', line 46 def payload .fetch(:payload) end |
#subject ⇒ Object
38 39 40 |
# File 'lib/fare/publisher.rb', line 38 def subject .fetch(:subject) end |
#topic ⇒ Object
18 19 20 |
# File 'lib/fare/publisher.rb', line 18 def topic Fare.topic_adapter.fetch(topic_info.fetch("arn")) end |
#topic_info ⇒ Object
22 23 24 |
# File 'lib/fare/publisher.rb', line 22 def topic_info @topic_info ||= configuration.find_publishable_topic() end |
#version ⇒ Object
50 51 52 |
# File 'lib/fare/publisher.rb', line 50 def version topic_info.fetch("version") end |