Sha256: f64e1efd7dc66798a4c09f173dc90b114a140fbbd49b693ccecd53984a3c323b

Contents?: true

Size: 1.33 KB

Versions: 58

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module WaterDrop
  class Producer
    # Producer lifecycle status object representation
    class Status
      # States in which the producer can be
      LIFECYCLE = %i[
        initial
        configured
        connected
        closing
        closed
      ].freeze

      private_constant :LIFECYCLE

      # Creates a new instance of status with the initial state
      # @return [Status]
      def initialize
        @current = LIFECYCLE.first
      end

      # @return [Boolean] true if producer is in a active state. Active means, that we can start
      #   sending messages. Actives states are connected (connection established) or configured,
      #   which means, that producer is configured, but connection with Kafka is
      #   not yet established.
      def active?
        connected? || configured?
      end

      # @return [String] current status as a string
      def to_s
        @current.to_s
      end

      LIFECYCLE.each do |state|
        module_eval <<-RUBY, __FILE__, __LINE__ + 1
          # @return [Boolean] true if current status is as we want, otherwise false
          def #{state}?
            @current == :#{state}
          end

          # Sets a given state as current
          def #{state}!
            @current = :#{state}
          end
        RUBY
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
waterdrop-2.6.5 lib/waterdrop/producer/status.rb
waterdrop-2.6.4 lib/waterdrop/producer/status.rb
waterdrop-2.6.3 lib/waterdrop/producer/status.rb
waterdrop-2.6.2 lib/waterdrop/producer/status.rb
waterdrop-2.6.1 lib/waterdrop/producer/status.rb
waterdrop-2.6.1.beta1 lib/waterdrop/producer/status.rb
waterdrop-2.6.0 lib/waterdrop/producer/status.rb
waterdrop-2.5.3 lib/waterdrop/producer/status.rb
waterdrop-2.5.2 lib/waterdrop/producer/status.rb
waterdrop-2.5.1 lib/waterdrop/producer/status.rb
waterdrop-2.5.0 lib/waterdrop/producer/status.rb
waterdrop-2.4.11 lib/waterdrop/producer/status.rb
waterdrop-2.4.10 lib/waterdrop/producer/status.rb
waterdrop-2.4.9 lib/waterdrop/producer/status.rb
waterdrop-2.4.8 lib/waterdrop/producer/status.rb
waterdrop-2.4.7 lib/waterdrop/producer/status.rb
waterdrop-2.4.6 lib/waterdrop/producer/status.rb
waterdrop-2.4.5 lib/waterdrop/producer/status.rb
waterdrop-2.4.4 lib/waterdrop/producer/status.rb
waterdrop-2.4.3 lib/waterdrop/producer/status.rb