class Shrine::Storage::Memory

  1. lib/shrine/storage/memory.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. clear!
  2. delete
  3. delete_prefixed
  4. exists?
  5. open
  6. store
  7. upload
  8. url

Attributes

store [R]

Public Class methods

new(store = {})
[show source]
   # File lib/shrine/storage/memory.rb
11 def initialize(store = {})
12   @store = store
13 end

Public Instance methods

clear!()
[show source]
   # File lib/shrine/storage/memory.rb
44 def clear!
45   store.clear
46 end
delete(id)
[show source]
   # File lib/shrine/storage/memory.rb
35 def delete(id)
36   store.delete(id)
37 end
delete_prefixed(delete_prefix)
[show source]
   # File lib/shrine/storage/memory.rb
39 def delete_prefixed(delete_prefix)
40   delete_prefix = delete_prefix.chomp("/") + "/"
41   store.delete_if { |key, _value| key.start_with?(delete_prefix) }
42 end
exists?(id)
[show source]
   # File lib/shrine/storage/memory.rb
27 def exists?(id)
28   store.key?(id)
29 end
open(id, **)
[show source]
   # File lib/shrine/storage/memory.rb
19 def open(id, **)
20   io = StringIO.new(store.fetch(id))
21   io.set_encoding(io.string.encoding) # Ruby 2.7.0 – https://bugs.ruby-lang.org/issues/16497
22   io
23 rescue KeyError
24   raise Shrine::FileNotFound, "file #{id.inspect} not found on storage"
25 end
upload(io, id, **)
[show source]
   # File lib/shrine/storage/memory.rb
15 def upload(io, id, **)
16   store[id] = io.read
17 end
url(id, *)
[show source]
   # File lib/shrine/storage/memory.rb
31 def url(id, *)
32   "memory://#{id}"
33 end