Class: HLS::Storage::Memory::Object
- Inherits:
-
Object
- Object
- HLS::Storage::Memory::Object
- Defined in:
- lib/hls/storage.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(store:, mutex:, key:, signing_ttl:) ⇒ Object
constructor
A new instance of Object.
- #presigned_url(_verb = :get, expires_in: @signing_ttl, **_) ⇒ Object
- #put(body:, content_type: "application/octet-stream", cache_control: nil) ⇒ Object
Constructor Details
#initialize(store:, mutex:, key:, signing_ttl:) ⇒ Object
Returns a new instance of Object.
98 99 100 101 102 103 |
# File 'lib/hls/storage.rb', line 98 def initialize(store:, mutex:, key:, signing_ttl:) @store = store @mutex = mutex @key = key @signing_ttl = signing_ttl end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
96 97 98 |
# File 'lib/hls/storage.rb', line 96 def key @key end |
Instance Method Details
#get ⇒ Object
105 106 107 108 109 |
# File 'lib/hls/storage.rb', line 105 def get entry = @mutex.synchronize { @store[@key] } raise KeyError, "no object at #{@key}" if entry.nil? Response.new(body: StringIO.new(entry[:body].to_s), content_type: entry[:content_type]) end |
#presigned_url(_verb = :get, expires_in: @signing_ttl, **_) ⇒ Object
123 124 125 |
# File 'lib/hls/storage.rb', line 123 def presigned_url(_verb = :get, expires_in: @signing_ttl, **_) "memory://#{@key}?expires_in=#{expires_in}" end |
#put(body:, content_type: "application/octet-stream", cache_control: nil) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/hls/storage.rb', line 111 def put(body:, content_type: "application/octet-stream", cache_control: nil) body_str = body.respond_to?(:read) ? body.read : body.to_s @mutex.synchronize do @store[@key] = { body: body_str, content_type: content_type, cache_control: cache_control } end PutResponse.new(etag: %("#{Digest::MD5.hexdigest(body_str)}")) end |