Class: Mistri::Workspace::Memory
- Inherits:
-
Object
- Object
- Mistri::Workspace::Memory
- Defined in:
- lib/mistri/workspace/memory.rb
Instance Method Summary collapse
- #delete(path) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #list(prefix = nil) ⇒ Object
- #read(path) ⇒ Object
- #write(path, content) ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
13 14 15 16 |
# File 'lib/mistri/workspace/memory.rb', line 13 def initialize @documents = {} @mutex = Mutex.new end |
Instance Method Details
#delete(path) ⇒ Object
27 28 29 30 |
# File 'lib/mistri/workspace/memory.rb', line 27 def delete(path) @mutex.synchronize { @documents.delete(path.to_s) } nil end |
#list(prefix = nil) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/mistri/workspace/memory.rb', line 32 def list(prefix = nil) @mutex.synchronize do keys = @documents.keys.sort prefix ? keys.select { |key| key.start_with?(prefix.to_s) } : keys end end |
#read(path) ⇒ Object
18 19 20 |
# File 'lib/mistri/workspace/memory.rb', line 18 def read(path) @mutex.synchronize { @documents[path.to_s] } end |
#write(path, content) ⇒ Object
22 23 24 25 |
# File 'lib/mistri/workspace/memory.rb', line 22 def write(path, content) @mutex.synchronize { @documents[path.to_s] = content.to_s.dup.freeze } nil end |