Class: Legion::Trigger::Envelope
- Inherits:
-
Object
- Object
- Legion::Trigger::Envelope
- Defined in:
- lib/legion/trigger/envelope.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#correlation_id ⇒ Object
readonly
Returns the value of attribute correlation_id.
-
#delivery_id ⇒ Object
readonly
Returns the value of attribute delivery_id.
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#received_at ⇒ Object
readonly
Returns the value of attribute received_at.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#verified ⇒ Object
readonly
Returns the value of attribute verified.
Instance Method Summary collapse
-
#initialize(source:, event_type:, payload:, action: nil, delivery_id: nil, verified: false, correlation_id: nil) ⇒ Envelope
constructor
rubocop:disable Metrics/ParameterLists.
- #routing_key ⇒ Object
- #to_h ⇒ Object
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
#action ⇒ Object (readonly)
Returns the value of attribute action.
6 7 8 |
# File 'lib/legion/trigger/envelope.rb', line 6 def action @action end |
#correlation_id ⇒ Object (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_id ⇒ Object (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_type ⇒ Object (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 |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
6 7 8 |
# File 'lib/legion/trigger/envelope.rb', line 6 def payload @payload end |
#received_at ⇒ Object (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 |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/legion/trigger/envelope.rb', line 6 def source @source end |
#verified ⇒ Object (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_key ⇒ Object
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_h ⇒ Object
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 |