Class: Karafka::Web::Tracking::Helpers::Ttls::Array
- Inherits:
 - 
      Object
      
        
- Object
 - Karafka::Web::Tracking::Helpers::Ttls::Array
 
 
- Includes:
 - Enumerable, Core::Helpers::Time
 
- Defined in:
 - lib/karafka/web/tracking/helpers/ttls/array.rb
 
Overview
Array that allows us to store data points that expire over time automatically.
Instance Method Summary collapse
- 
  
    
      #<<(value)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Added element.
 - 
  
    
      #each  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Iterates over only active elements.
 - 
  
    
      #empty?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Is the array empty.
 - 
  
    
      #initialize(ttl)  ⇒ Array 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Array.
 - 
  
    
      #inspect  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Thread-safe inspection string.
 - 
  
    
      #samples  ⇒ Hash 
    
    
  
  
  
  
  
  
  
  
  
    
Samples that are within our TTL time window with the times.
 - 
  
    
      #to_a  ⇒ ::Array 
    
    
  
  
  
  
  
  
  
  
  
    
Pure array version with only active elements.
 
Constructor Details
#initialize(ttl) ⇒ Array
Returns a new instance of Array.
      15 16 17 18  | 
    
      # File 'lib/karafka/web/tracking/helpers/ttls/array.rb', line 15 def initialize(ttl) @ttl = ttl @accu = [] end  | 
  
Instance Method Details
#<<(value) ⇒ Object
Returns added element.
      31 32 33 34 35 36 37  | 
    
      # File 'lib/karafka/web/tracking/helpers/ttls/array.rb', line 31 def <<(value) @accu << { value: value, added_at: monotonic_now } clear value end  | 
  
#each ⇒ Object
Iterates over only active elements
      21 22 23 24 25 26 27  | 
    
      # File 'lib/karafka/web/tracking/helpers/ttls/array.rb', line 21 def each clear @accu.each do |sample| yield sample[:value] end end  | 
  
#empty? ⇒ Boolean
Returns is the array empty.
      40 41 42 43  | 
    
      # File 'lib/karafka/web/tracking/helpers/ttls/array.rb', line 40 def empty? clear @accu.empty? end  | 
  
#inspect ⇒ String
Returns thread-safe inspection string.
      60 61 62 63 64 65 66 67 68  | 
    
      # File 'lib/karafka/web/tracking/helpers/ttls/array.rb', line 60 def inspect clear size = @accu.size parts = ["ttl=#{@ttl}ms"] parts << "size=#{size}" "#<#{self.class.name}:#{format('%#x', object_id)} #{parts.join(' ')}>" end  | 
  
#samples ⇒ Hash
Samples that are within our TTL time window with the times
      48 49 50 51  | 
    
      # File 'lib/karafka/web/tracking/helpers/ttls/array.rb', line 48 def samples clear @accu end  | 
  
#to_a ⇒ ::Array
Returns pure array version with only active elements.
      54 55 56 57  | 
    
      # File 'lib/karafka/web/tracking/helpers/ttls/array.rb', line 54 def to_a clear super end  |