Class: Makura::UUIDCache

Inherits:
Object
  • Object
show all
Defined in:
lib/makura/uuid_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, min = 500, max = 1500, pretty = true) ⇒ UUIDCache

Returns a new instance of UUIDCache.



5
6
7
8
# File 'lib/makura/uuid_cache.rb', line 5

def initialize(server, min = 500, max = 1500, pretty = true)
  @server, @min, @max, @pretty = server, min, max, pretty
  @uuids = []
end

Instance Attribute Details

#maxObject

Returns the value of attribute max.



3
4
5
# File 'lib/makura/uuid_cache.rb', line 3

def max
  @max
end

#minObject

Returns the value of attribute min.



3
4
5
# File 'lib/makura/uuid_cache.rb', line 3

def min
  @min
end

#prettyObject

Returns the value of attribute pretty.



3
4
5
# File 'lib/makura/uuid_cache.rb', line 3

def pretty
  @pretty
end

#serverObject

Returns the value of attribute server.



3
4
5
# File 'lib/makura/uuid_cache.rb', line 3

def server
  @server
end

Instance Method Details

#fetch(count = 0) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/makura/uuid_cache.rb', line 15

def fetch(count = 0)
  todo = max - @uuids.size
  count = [min, todo, max].sort[1]
  uuids = @server.get('/_uuids', :count => count)['uuids']
  uuids.map!{|u| Makura.pretty_from_md5(u) } if pretty
  @uuids.concat(uuids)
end

#nextObject



10
11
12
13
# File 'lib/makura/uuid_cache.rb', line 10

def next
  fetch if @uuids.size < min
  @uuids.shift
end