Class: Refile::Memory::Backend
- Inherits:
-
Object
- Object
- Refile::Memory::Backend
- Defined in:
- lib/refile/memory.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Instance Method Summary collapse
- #clear!(confirm = nil) ⇒ Object
- #delete(id) ⇒ Object
- #exists?(id) ⇒ Boolean
- #get(id) ⇒ Object
-
#initialize(max_size: nil, hasher: Refile::RandomHasher.new) ⇒ Backend
constructor
A new instance of Backend.
- #open(id) ⇒ Object
- #read(id) ⇒ Object
- #size(id) ⇒ Object
- #upload(uploadable) ⇒ Object
Constructor Details
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
7 8 9 |
# File 'lib/refile/memory.rb', line 7 def directory @directory end |
Instance Method Details
#clear!(confirm = nil) ⇒ Object
49 50 51 52 |
# File 'lib/refile/memory.rb', line 49 def clear!(confirm = nil) raise ArgumentError, "are you sure? this will remove all files in the backend, call as `clear!(:confirm)` if you're sure you want to do this" unless confirm == :confirm @store = {} end |
#delete(id) ⇒ Object
29 30 31 |
# File 'lib/refile/memory.rb', line 29 def delete(id) @store.delete(id) end |
#exists?(id) ⇒ Boolean
45 46 47 |
# File 'lib/refile/memory.rb', line 45 def exists?(id) @store.has_key?(id) end |
#get(id) ⇒ Object
25 26 27 |
# File 'lib/refile/memory.rb', line 25 def get(id) Refile::File.new(self, id) end |
#open(id) ⇒ Object
33 34 35 |
# File 'lib/refile/memory.rb', line 33 def open(id) StringIO.new(@store[id]) end |
#read(id) ⇒ Object
37 38 39 |
# File 'lib/refile/memory.rb', line 37 def read(id) @store[id] end |
#size(id) ⇒ Object
41 42 43 |
# File 'lib/refile/memory.rb', line 41 def size(id) @store[id].bytesize if exists?(id) end |