Class: JetstreamBridge::Models::Event::PayloadAccessor
- Inherits:
-
Object
- Object
- JetstreamBridge::Models::Event::PayloadAccessor
show all
- Defined in:
- lib/jetstream_bridge/models/event.rb
Overview
Wraps a Hash payload to allow method-style access to its keys.
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PayloadAccessor.
65
66
67
|
# File 'lib/jetstream_bridge/models/event.rb', line 65
def initialize(payload)
@payload = payload.is_a?(Hash) ? payload.transform_keys(&:to_s) : {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
69
70
71
72
73
|
# File 'lib/jetstream_bridge/models/event.rb', line 69
def method_missing(method_name, *args)
return @payload[method_name.to_s] if args.empty? && @payload.key?(method_name.to_s)
super
end
|
Instance Method Details
#[](key) ⇒ Object
79
80
81
|
# File 'lib/jetstream_bridge/models/event.rb', line 79
def [](key)
@payload[key.to_s]
end
|
#dig(*keys) ⇒ Object
83
84
85
|
# File 'lib/jetstream_bridge/models/event.rb', line 83
def dig(*keys)
@payload.dig(*keys.map(&:to_s))
end
|
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
75
76
77
|
# File 'lib/jetstream_bridge/models/event.rb', line 75
def respond_to_missing?(method_name, _include_private = false)
@payload.key?(method_name.to_s) || super
end
|
#to_h ⇒ Object
Also known as:
to_hash
87
88
89
|
# File 'lib/jetstream_bridge/models/event.rb', line 87
def to_h
@payload
end
|