Class: Legion::Trigger::Envelope

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/trigger/envelope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, event_type:, payload:, action: nil, delivery_id: nil, verified: false, correlation_id: nil) ⇒ Envelope

rubocop:disable Metrics/ParameterLists



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/legion/trigger/envelope.rb', line 9

def initialize(source:, event_type:, payload:, action: nil, delivery_id: nil, # rubocop:disable Metrics/ParameterLists
               verified: false, correlation_id: nil)
  @source         = source
  @event_type     = event_type
  @action         = action
  @delivery_id    = delivery_id
  @verified       = verified
  @correlation_id = correlation_id || generate_correlation_id
  @received_at    = Time.now.iso8601
  @payload        = payload
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



6
7
8
# File 'lib/legion/trigger/envelope.rb', line 6

def action
  @action
end

#correlation_idObject (readonly)

Returns the value of attribute correlation_id.



6
7
8
# File 'lib/legion/trigger/envelope.rb', line 6

def correlation_id
  @correlation_id
end

#delivery_idObject (readonly)

Returns the value of attribute delivery_id.



6
7
8
# File 'lib/legion/trigger/envelope.rb', line 6

def delivery_id
  @delivery_id
end

#event_typeObject (readonly)

Returns the value of attribute event_type.



6
7
8
# File 'lib/legion/trigger/envelope.rb', line 6

def event_type
  @event_type
end

#payloadObject (readonly)

Returns the value of attribute payload.



6
7
8
# File 'lib/legion/trigger/envelope.rb', line 6

def payload
  @payload
end

#received_atObject (readonly)

Returns the value of attribute received_at.



6
7
8
# File 'lib/legion/trigger/envelope.rb', line 6

def received_at
  @received_at
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/legion/trigger/envelope.rb', line 6

def source
  @source
end

#verifiedObject (readonly)

Returns the value of attribute verified.



6
7
8
# File 'lib/legion/trigger/envelope.rb', line 6

def verified
  @verified
end

Instance Method Details

#routing_keyObject



21
22
23
24
25
# File 'lib/legion/trigger/envelope.rb', line 21

def routing_key
  safe_event = event_type.to_s.gsub(/[^a-zA-Z0-9_-]/, '_')[0, 64]
  parts = ['trigger', source, safe_event].reject { |p| p.nil? || p.empty? }
  parts.join('.')
end

#to_hObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/legion/trigger/envelope.rb', line 27

def to_h
  {
    source:         source,
    event_type:     event_type,
    action:         action,
    delivery_id:    delivery_id,
    verified:       verified,
    correlation_id: correlation_id,
    received_at:    received_at,
    payload:        payload
  }
end