Class: Karafka::ExecutionMode
- Inherits:
-
Object
- Object
- Karafka::ExecutionMode
- Defined in:
- lib/karafka/execution_mode.rb
Overview
Represents the execution mode state of the Karafka server. Provides a cleaner API for checking and setting execution modes, encapsulating the mode logic and removing the need for symbol comparisons throughout the codebase.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares the execution mode with another object.
-
#initialize(mode = :standalone) ⇒ ExecutionMode
constructor
A new instance of ExecutionMode.
-
#to_s ⇒ String
String representation of the current mode.
-
#to_sym ⇒ Symbol
Symbol representation of the current mode.
Constructor Details
#initialize(mode = :standalone) ⇒ ExecutionMode
Returns a new instance of ExecutionMode.
30 31 32 |
# File 'lib/karafka/execution_mode.rb', line 30 def initialize(mode = :standalone) self.mode = mode end |
Instance Method Details
#==(other) ⇒ Boolean
Compares the execution mode with another object. Supports comparison with symbols, strings, and other ExecutionMode instances for backward compatibility with existing code.
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/karafka/execution_mode.rb', line 75 def ==(other) case other when Symbol @mode == other when String @mode.to_s == other when ExecutionMode @mode == other.to_sym else false end end |
#to_s ⇒ String
Returns string representation of the current mode.
51 52 53 |
# File 'lib/karafka/execution_mode.rb', line 51 def to_s @mode.to_s end |
#to_sym ⇒ Symbol
Returns symbol representation of the current mode.
56 57 58 |
# File 'lib/karafka/execution_mode.rb', line 56 def to_sym @mode end |