Class: Fare::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/fare/publisher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, options) ⇒ Publisher



8
9
10
11
# File 'lib/fare/publisher.rb', line 8

def initialize(configuration, options)
  @configuration = configuration
  @options = options
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



6
7
8
# File 'lib/fare/publisher.rb', line 6

def configuration
  @configuration
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/fare/publisher.rb', line 6

def options
  @options
end

Instance Method Details

#actionObject



42
43
44
# File 'lib/fare/publisher.rb', line 42

def action
  options.fetch(:action)
end

#app_nameObject



54
55
56
# File 'lib/fare/publisher.rb', line 54

def app_name
  configuration.app_name
end

#callObject



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

#eventObject



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

#payloadObject



46
47
48
# File 'lib/fare/publisher.rb', line 46

def payload
  options.fetch(:payload)
end

#subjectObject



38
39
40
# File 'lib/fare/publisher.rb', line 38

def subject
  options.fetch(:subject)
end

#topicObject



18
19
20
# File 'lib/fare/publisher.rb', line 18

def topic
  Fare.topic_adapter.fetch(topic_info.fetch("arn"))
end

#topic_infoObject



22
23
24
# File 'lib/fare/publisher.rb', line 22

def topic_info
  @topic_info ||= configuration.find_publishable_topic(options)
end

#versionObject



50
51
52
# File 'lib/fare/publisher.rb', line 50

def version
  topic_info.fetch("version")
end