Class: Polipus::Storage::MemoryStore

Inherits:
Base
  • Object
show all
Defined in:
lib/polipus/storage/memory_store.rb

Instance Attribute Summary

Attributes inherited from Base

#include_query_string_in_uuid

Instance Method Summary collapse

Constructor Details

#initialize(_options = {}) ⇒ MemoryStore

Returns a new instance of MemoryStore.



5
6
7
8
# File 'lib/polipus/storage/memory_store.rb', line 5

def initialize(_options = {})
  @store = {}
  @semaphore = Mutex.new
end

Instance Method Details

#add(page) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/polipus/storage/memory_store.rb', line 10

def add(page)
  @semaphore.synchronize do
    u = uuid(page)
    @store[u] = page
    u
  end
end

#clearObject



48
49
50
51
52
# File 'lib/polipus/storage/memory_store.rb', line 48

def clear
  @semaphore.synchronize do
    @store = Hash.new
  end
end

#countObject



36
37
38
39
40
# File 'lib/polipus/storage/memory_store.rb', line 36

def count
  @semaphore.synchronize do
    @store.count
  end
end

#eachObject



42
43
44
45
46
# File 'lib/polipus/storage/memory_store.rb', line 42

def each
  @store.each do |k, v|
    yield k, v
  end
end

#exists?(page) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/polipus/storage/memory_store.rb', line 18

def exists?(page)
  @semaphore.synchronize do
    @store.key?(uuid(page))
  end
end

#get(page) ⇒ Object



24
25
26
27
28
# File 'lib/polipus/storage/memory_store.rb', line 24

def get(page)
  @semaphore.synchronize do
    @store[uuid(page)]
  end
end

#remove(page) ⇒ Object



30
31
32
33
34
# File 'lib/polipus/storage/memory_store.rb', line 30

def remove(page)
  @semaphore.synchronize do
    @store.delete(uuid(page))
  end
end