Class: Makura::UUIDCache
- Inherits:
-
Object
- Object
- Makura::UUIDCache
- Defined in:
- lib/makura/uuid_cache.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
Returns the value of attribute max.
-
#min ⇒ Object
Returns the value of attribute min.
-
#pretty ⇒ Object
Returns the value of attribute pretty.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
- #fetch(count = 0) ⇒ Object
-
#initialize(server, min = 500, max = 1500, pretty = true) ⇒ UUIDCache
constructor
A new instance of UUIDCache.
- #next ⇒ Object
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
#max ⇒ Object
Returns the value of attribute max.
3 4 5 |
# File 'lib/makura/uuid_cache.rb', line 3 def max @max end |
#min ⇒ Object
Returns the value of attribute min.
3 4 5 |
# File 'lib/makura/uuid_cache.rb', line 3 def min @min end |
#pretty ⇒ Object
Returns the value of attribute pretty.
3 4 5 |
# File 'lib/makura/uuid_cache.rb', line 3 def pretty @pretty end |
#server ⇒ Object
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 |
#next ⇒ Object
10 11 12 13 |
# File 'lib/makura/uuid_cache.rb', line 10 def next fetch if @uuids.size < min @uuids.shift end |