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.8.0 lib/waterdrop/producer/status.rb
waterdrop-2.7.4 lib/waterdrop/producer/status.rb
waterdrop-2.7.3 lib/waterdrop/producer/status.rb
waterdrop-2.7.0 lib/waterdrop/producer/status.rb
waterdrop-2.7.0.rc2 lib/waterdrop/producer/status.rb
waterdrop-2.7.0.rc1 lib/waterdrop/producer/status.rb
waterdrop-2.7.0.beta2 lib/waterdrop/producer/status.rb
waterdrop-2.7.0.beta1 lib/waterdrop/producer/status.rb
waterdrop-2.7.0.alpha3 lib/waterdrop/producer/status.rb
waterdrop-2.7.0.alpha2 lib/waterdrop/producer/status.rb
waterdrop-2.7.0.alpha1 lib/waterdrop/producer/status.rb
waterdrop-2.6.14 lib/waterdrop/producer/status.rb
waterdrop-2.6.13 lib/waterdrop/producer/status.rb
waterdrop-2.6.12 lib/waterdrop/producer/status.rb
waterdrop-2.6.11 lib/waterdrop/producer/status.rb
waterdrop-2.6.10 lib/waterdrop/producer/status.rb
waterdrop-2.6.9 lib/waterdrop/producer/status.rb
waterdrop-2.6.8 lib/waterdrop/producer/status.rb
waterdrop-2.6.7 lib/waterdrop/producer/status.rb
waterdrop-2.6.6 lib/waterdrop/producer/status.rb