Class: StrokeDB::MemoryStorage
- Inherits:
-
Storage
show all
- Defined in:
- lib/strokedb/stores/memory_storage.rb
Instance Attribute Summary
Attributes inherited from Storage
#authoritative_source
Instance Method Summary
collapse
#add_chained_storage!, #has_chained_storage?, #remove_chained_storage!, #save_with_chained_storages!, #save_without_chained_storages!, #sync_chained_storage!, #sync_chained_storages!
Constructor Details
#initialize(options = {}) ⇒ MemoryStorage
Returns a new instance of MemoryStorage.
4
5
6
7
|
# File 'lib/strokedb/stores/memory_storage.rb', line 4
def initialize(options = {})
@options = options.stringify_keys
clear!
end
|
Instance Method Details
60
61
62
|
# File 'lib/strokedb/stores/memory_storage.rb', line 60
def clear!
@container = SimpleSkiplist.new
end
|
64
65
|
# File 'lib/strokedb/stores/memory_storage.rb', line 64
def close!
end
|
#each(options = {}) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/strokedb/stores/memory_storage.rb', line 40
def each(options = {})
after = options[:after_timestamp]
include_versions = options[:include_versions]
@container.each do |key, value|
next if after && (value[1] <= after)
if uuid_match = key.match(/^#{UUID_RE}$/) || (include_versions && uuid_match = key.match(/#{UUID_RE}./) )
yield Document.from_raw(options[:store],value[0])
end
end
end
|
#find(uuid, version = nil, opts = {}, &block) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/strokedb/stores/memory_storage.rb', line 13
def find(uuid, version=nil, opts = {},&block)
uuid_version = uuid + (version ? ".#{version}" : "")
unless raw_doc = read(uuid_version)
authoritative_source.find(uuid,version,opts,&block) if authoritative_source
else
unless opts[:no_instantiation]
doc = Document.from_raw(opts[:store], raw_doc.freeze, &block) doc.extend(VersionedDocument) if version
doc
else
raw_doc
end
end
end
|
#head_version(uuid, opts = {}) ⇒ Object
34
35
36
37
38
|
# File 'lib/strokedb/stores/memory_storage.rb', line 34
def head_version(uuid, opts = {})
if doc = find(uuid,nil, opts)
doc.version
end
end
|
#include?(uuid, version = nil) ⇒ Boolean
Also known as:
contains?
28
29
30
31
|
# File 'lib/strokedb/stores/memory_storage.rb', line 28
def include?(uuid,version=nil)
uuid_version = uuid + (version ? ".#{version}" : "")
!@container.find(uuid_version).nil?
end
|
51
52
53
54
55
56
57
58
|
# File 'lib/strokedb/stores/memory_storage.rb', line 51
def perform_save!(document, timestamp, options = {})
uuid = document.uuid
version = document.version
raw_document = document.to_raw
uuid_version = uuid + (version ? ".#{version}" : "")
write(uuid, raw_document, timestamp) if options[:head] || !document.is_a?(VersionedDocument)
write(uuid_version, raw_document, timestamp) unless options[:head]
end
|
#save_as_head!(document, timestamp) ⇒ Object
9
10
11
|
# File 'lib/strokedb/stores/memory_storage.rb', line 9
def save_as_head!(document, timestamp)
save!(document,timestamp, :head => true)
end
|