Class: ROM::Kafka::Brokers::Broker

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/kafka/brokers/broker.rb

Overview

Describes an address to a brocker

Examples:

broker = Broker.new host: "localhost:9092"
broker.to_s # => "localhost:9092"

broker = Broker.new host: "localhost", port: 9092
broker.to_s # => "localhost:9092"

broker = Broker.new host: "localhost:9092", port: 9093
broker.to_s # => "localhost:9092"

Author:

Constant Summary collapse

HOST =

Regex to extract host from address line

%r{^\w+(\:\/\/)?\S+(?=\:)|\S+}.freeze
PORT =

Regex to extract port from address line

/(?!\:)\d{4,5}$/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Broker

Initializes a value object from host line and port

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :host (#to_s) — default: "localhost"
  • :port (#to_i) — default: 9092


43
44
45
46
47
# File 'lib/rom/kafka/brokers/broker.rb', line 43

def initialize(options = {})
  line  = options.fetch(:host) { "localhost" }
  @host = line[HOST]
  @port = (line[PORT] || options.fetch(:port) { 9092 }).to_i
end

Instance Attribute Details

#hostString (readonly)

Returns the host of the broker.

Returns:

  • (String)

    the host of the broker



30
31
32
# File 'lib/rom/kafka/brokers/broker.rb', line 30

def host
  @host
end

#portInteger (readonly)

Returns the port of the broker.

Returns:

  • (Integer)

    the port of the broker



36
37
38
# File 'lib/rom/kafka/brokers/broker.rb', line 36

def port
  @port
end

Instance Method Details

#to_sString

Returns the string representation of the broker in “host:port” format

Returns:

  • (String)


53
54
55
# File 'lib/rom/kafka/brokers/broker.rb', line 53

def to_s
  "#{host}:#{port}"
end