Class: Wye::Distributor::Sticky

Inherits:
Object
  • Object
show all
Defined in:
lib/wye/distributor/sticky.rb

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Sticky

Returns a new instance of Sticky.



6
7
8
# File 'lib/wye/distributor/sticky.rb', line 6

def initialize(values)
  @values = values
end

Instance Method Details

#next(id) ⇒ Object



10
11
12
# File 'lib/wye/distributor/sticky.rb', line 10

def next(id)
  (mod = @values.length) > 0 ? @values[Zlib.crc32(id.to_s) % mod] : nil
end