Class: KafkaRest::Partition

Inherits:
Object
  • Object
show all
Includes:
Producable
Defined in:
lib/kafka_rest/partition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Producable

#produce

Constructor Details

#initialize(client, topic, id, raw = EMPTY_STRING) ⇒ Partition

Returns a new instance of Partition.



7
8
9
10
11
12
# File 'lib/kafka_rest/partition.rb', line 7

def initialize(client, topic, id, raw = EMPTY_STRING)
  @client = client
  @topic = topic
  @id = id
  @raw = raw
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/kafka_rest/partition.rb', line 5

def client
  @client
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/kafka_rest/partition.rb', line 5

def id
  @id
end

#rawObject (readonly)

Returns the value of attribute raw.



5
6
7
# File 'lib/kafka_rest/partition.rb', line 5

def raw
  @raw
end

#topicObject (readonly)

Returns the value of attribute topic.



5
6
7
# File 'lib/kafka_rest/partition.rb', line 5

def topic
  @topic
end

Instance Method Details

#getObject



14
15
16
# File 'lib/kafka_rest/partition.rb', line 14

def get
  client.request(partition_path).tap { |res| @raw = res }
end

#to_sObject



18
19
20
21
22
23
# File 'lib/kafka_rest/partition.rb', line 18

def to_s
  res = "Partition{topic=\"#{topic.name}\", id=#{id}".freeze
  res += ", leader=#{raw['leader']}".freeze unless raw.empty?
  res += ", replicas=#{raw['replicas'].size}".freeze unless raw.empty?
  res += RIGHT_BRACE
end