Class: Hermes::BaseEvent

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/hermes/base_event.rb

Direct Known Subclasses

RpcClient::ResponseEvent

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#origin_bodyObject

Returns the value of attribute origin_body.



6
7
8
# File 'lib/hermes/base_event.rb', line 6

def origin_body
  @origin_body
end

#origin_headersObject

Returns the value of attribute origin_headers.



6
7
8
# File 'lib/hermes/base_event.rb', line 6

def origin_headers
  @origin_headers
end

Class Method Details

.from_body_and_headers(body, headers) ⇒ Object



8
9
10
11
12
13
# File 'lib/hermes/base_event.rb', line 8

def self.from_body_and_headers(body, headers)
  new(body.deep_symbolize_keys).tap do |event|
    event.origin_body = body
    event.origin_headers = headers
  end
end

.routing_keyObject



15
16
17
18
19
20
21
22
23
# File 'lib/hermes/base_event.rb', line 15

def self.routing_key
  names = to_s.split("::")
  starting_index = if names.first.include?(EVENTS_NAMESPACE)
    1
  else
    0
  end
  names[starting_index..-1].map(&:underscore).map(&:downcase).join(".")
end

Instance Method Details

#routing_keyObject



25
26
27
# File 'lib/hermes/base_event.rb', line 25

def routing_key
  self.class.routing_key
end

#to_headersObject



33
34
35
36
37
38
# File 'lib/hermes/base_event.rb', line 33

def to_headers
  Hermes::B3PropagationModelHeaders
    .new(trace_context)
    .as_json
    .merge("service" => trace_context.service)
end

#trace_contextObject



40
41
42
# File 'lib/hermes/base_event.rb', line 40

def trace_context
  @trace_context ||= Hermes::TraceContext.new(origin_headers)
end

#versionObject



29
30
31
# File 'lib/hermes/base_event.rb', line 29

def version
  1
end