Class: Lepus::Message::DeliveryInfo
- Inherits:
-
Object
- Object
- Lepus::Message::DeliveryInfo
- Defined in:
- lib/lepus/message/delivery_info.rb
Overview
Internal data class representing delivery information. Provides the same interface as Bunny::DeliveryInfo (duck typing).
Constant Summary collapse
- KNOWN_ATTRIBUTES =
%i[delivery_tag redelivered exchange routing_key consumer_tag].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Hash-style access to properties (compatible with Bunny::DeliveryInfo).
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(**attrs) ⇒ DeliveryInfo
constructor
A new instance of DeliveryInfo.
-
#method_missing(method_name, *args) ⇒ Object
Support dynamic attribute access for compatibility.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(**attrs) ⇒ DeliveryInfo
Returns a new instance of DeliveryInfo.
22 23 24 25 26 27 28 29 |
# File 'lib/lepus/message/delivery_info.rb', line 22 def initialize(**attrs) @delivery_tag = attrs[:delivery_tag] @redelivered = attrs.fetch(:redelivered, false) @exchange = attrs[:exchange] @routing_key = attrs[:routing_key] @consumer_tag = attrs[:consumer_tag] @extra_attributes = attrs.reject { |k, _| KNOWN_ATTRIBUTES.include?(k) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
Support dynamic attribute access for compatibility
49 50 51 52 53 54 |
# File 'lib/lepus/message/delivery_info.rb', line 49 def method_missing(method_name, *args) return super if method_name.to_s.end_with?("=") return super if args.any? self[method_name] end |
Class Method Details
.from_bunny(bunny_delivery_info) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/lepus/message/delivery_info.rb', line 12 def self.from_bunny(bunny_delivery_info) new( delivery_tag: bunny_delivery_info.delivery_tag, redelivered: bunny_delivery_info.redelivered, exchange: bunny_delivery_info.exchange, routing_key: bunny_delivery_info.routing_key, consumer_tag: bunny_delivery_info.consumer_tag ) end |
Instance Method Details
#[](key) ⇒ Object?
Hash-style access to properties (compatible with Bunny::DeliveryInfo)
44 45 46 |
# File 'lib/lepus/message/delivery_info.rb', line 44 def [](key) to_h[key.to_sym] end |
#eql?(other) ⇒ Boolean Also known as: ==
60 61 62 63 64 65 66 67 68 |
# File 'lib/lepus/message/delivery_info.rb', line 60 def eql?(other) return false unless other.is_a?(self.class) delivery_tag == other.delivery_tag && redelivered == other.redelivered && exchange == other.exchange && routing_key == other.routing_key && consumer_tag == other.consumer_tag end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
56 57 58 |
# File 'lib/lepus/message/delivery_info.rb', line 56 def respond_to_missing?(method_name, include_private = false) !method_name.to_s.end_with?("=") || super end |
#to_h ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/lepus/message/delivery_info.rb', line 31 def to_h { delivery_tag: delivery_tag, redelivered: redelivered, exchange: exchange, routing_key: routing_key, consumer_tag: consumer_tag }.merge(@extra_attributes) end |