Module: Karafka::Pro::Routing::Features::ConsumerGroups::DirectAssignments::Topic
- Defined in:
- lib/karafka/pro/routing/features/consumer_groups/direct_assignments/topic.rb
Overview
Topic extensions for direct assignments
Instance Method Summary collapse
-
#direct_assignments(*partitions_or_all) ⇒ Object
(also: #assign)
Allows for direct assignment of.
-
#initialize ⇒ Object
This method sets up the extra instance variable to nil before calling the parent class initializer.
-
#to_h ⇒ Hash
Topic with all its native configuration options plus direct assignments.
Instance Method Details
#direct_assignments(*partitions_or_all) ⇒ Object Also known as: assign
Allows for direct assignment of
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/karafka/pro/routing/features/consumer_groups/direct_assignments/topic.rb', line 61 def direct_assignments(*partitions_or_all) @direct_assignments ||= if partitions_or_all == [true] Config.new( active: true, partitions: true ) elsif partitions_or_all.size == 1 && partitions_or_all.first.is_a?(Range) partitions_or_all = partitions_or_all.first.to_a Config.new( active: true, partitions: partitions_or_all.to_h { |partition| [partition, true] } ) else Config.new( active: !partitions_or_all.empty?, partitions: partitions_or_all.to_h { |partition| [partition, true] } ) end end |
#initialize ⇒ Object
This method sets up the extra instance variable to nil before calling the parent class initializer. The explicit initialization to nil is included as an optimization for Ruby’s object shapes system, which improves memory layout and access performance.
43 44 45 46 |
# File 'lib/karafka/pro/routing/features/consumer_groups/direct_assignments/topic.rb', line 43 def initialize(...) @direct_assignments = nil super end |
#to_h ⇒ Hash
Returns topic with all its native configuration options plus direct assignments.
86 87 88 89 90 |
# File 'lib/karafka/pro/routing/features/consumer_groups/direct_assignments/topic.rb', line 86 def to_h super.merge( direct_assignments: direct_assignments.to_h ).freeze end |