Class: Karafka::Connection::Mode

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/connection/mode.rb

Overview

Note:

This class is used internally by the Client and is not part of the public API

Represents the connection mode state of the Kafka client. Encapsulates mode logic and provides a cleaner API for checking and setting connection modes, removing the need for symbol comparisons throughout the connection management code.

Examples:

Check if client is in subscribe mode (internal usage)

@mode.subscribe? #=> true

Set the connection mode to assign (internal usage)

@mode.assign!

Instance Method Summary collapse

Constructor Details

#initialize(mode = :subscribe) ⇒ Mode

Returns a new instance of Mode.

Parameters:

  • mode (Symbol) (defaults to: :subscribe)

    initial connection mode (defaults to :subscribe)

Raises:

  • (ArgumentError)

    when invalid mode is provided



29
30
31
# File 'lib/karafka/connection/mode.rb', line 29

def initialize(mode = :subscribe)
  self.mode = mode
end

Instance Method Details

#to_sString

Returns string representation of the current mode.

Returns:

  • (String)

    string representation of the current mode



50
51
52
# File 'lib/karafka/connection/mode.rb', line 50

def to_s
  @mode.to_s
end

#to_symSymbol

Returns symbol representation of the current mode.

Returns:

  • (Symbol)

    symbol representation of the current mode



55
56
57
# File 'lib/karafka/connection/mode.rb', line 55

def to_sym
  @mode
end