Class: Mailkube::Events::Node
- Inherits:
-
Object
- Object
- Mailkube::Events::Node
- Defined in:
- lib/mailkube/events/node.rb,
sig/mailkube/events/node.rbs
Overview
Event models are the one place this gem does not use Data.define.
The contract inverts the response-model rule for webhooks: unknown fields are preserved, not
dropped, at every depth. A Data has fixed members and drops them, so the decoded hash is
the state instead, and each subclass declares one-line readers over it.
Those readers are real defs, so they are declared here as def — attr_reader in these
signatures is reserved for the readers Data.define actually generates (see
sig/mailkube/types.rbs).
Direct Known Subclasses
DeliveryContext, DomainStatusData, DomainStatusPrevious, EngagementContext, Event, MessageContext, ScheduledContext, SendFailureContext, SuppressionContext, WebhookStatusData, WebhookStatusPrevious
Instance Attribute Summary collapse
-
#raw ⇒ Hash{String => Object}
readonly
The verbatim decoded object, unknown fields included.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
True when both are the same class over the same payload.
-
#[](key) ⇒ Object?
Read any field by its wire name, whether or not this release models it.
-
#block(type, key) ⇒ Object
Deliberately
untypedrather than a bounded generic: Ruby has no generics, and every caller is a one-line reader that already declares its own concrete return type — which is where the type belongs. -
#hash ⇒ Integer
A hash consistent with #==.
-
#initialize(raw) ⇒ Node
constructor
A new instance of Node.
-
#to_h ⇒ Hash{String => Object}
The verbatim decoded object, for logging or forwarding.
Constructor Details
#initialize(raw) ⇒ Node
Returns a new instance of Node.
27 28 29 30 |
# File 'lib/mailkube/events/node.rb', line 27 def initialize(raw) @raw = raw freeze end |
Instance Attribute Details
#raw ⇒ Hash{String => Object} (readonly)
Returns the verbatim decoded object, unknown fields included.
24 25 26 |
# File 'lib/mailkube/events/node.rb', line 24 def raw @raw end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns true when both are the same class over the same payload.
46 |
# File 'lib/mailkube/events/node.rb', line 46 def ==(other) = other.instance_of?(self.class) && other.raw == @raw |
#[](key) ⇒ Object?
Read any field by its wire name, whether or not this release models it.
This is the forward-compatibility escape hatch the contract asks for: a field the platform adds after this gem ships is reachable here on the day it appears.
39 |
# File 'lib/mailkube/events/node.rb', line 39 def [](key) = @raw[key] |
#block(type, key) ⇒ Object
Deliberately untyped rather than a bounded generic: Ruby has no generics, and every
caller is a one-line reader that already declares its own concrete return type — which is
where the type belongs.
59 |
# File 'lib/mailkube/events/node.rb', line 59 def block(type, key) = type.new(self[key] || {}) |
#hash ⇒ Integer
Returns a hash consistent with #==.
50 |
# File 'lib/mailkube/events/node.rb', line 50 def hash = [self.class, @raw].hash |
#to_h ⇒ Hash{String => Object}
Returns the verbatim decoded object, for logging or forwarding.
42 |
# File 'lib/mailkube/events/node.rb', line 42 def to_h = @raw |