Class: Aikido::Zen::CappedSet Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/aikido/zen/capped_collections.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides a FIFO set with a maximum size. Adding an element after the capacity has been reached kicks the oldest element in the set out, while maintaining the uniqueness property of a set (relying on #eql? and #hash).

Direct Known Subclasses

Aikido::Zen::Collector::Hosts

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capacity) ⇒ CappedSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CappedSet.



21
22
23
# File 'lib/aikido/zen/capped_collections.rb', line 21

def initialize(capacity)
  @data = CappedMap.new(capacity)
end

Instance Attribute Details

#capacityInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Integer)


19
20
21
# File 'lib/aikido/zen/capped_collections.rb', line 19

def capacity
  @capacity
end

Instance Method Details

#<<(element) ⇒ Object Also known as: add, push

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
# File 'lib/aikido/zen/capped_collections.rb', line 25

def <<(element)
  @data[element] = nil
  self
end

#as_jsonObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
# File 'lib/aikido/zen/capped_collections.rb', line 36

def as_json
  map(&:as_json)
end

#each(&b) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
# File 'lib/aikido/zen/capped_collections.rb', line 32

def each(&b)
  @data.each_key(&b)
end