Class: HLS::Storage::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/hls/storage.rb

Overview

In-memory bucket for tests. Backed by a hash protected by a single mutex — concurrent puts and gets across threads are safe.

Defined Under Namespace

Classes: Object, PutResponse, Response

Constant Summary collapse

DEFAULT_SIGNING_TTL =
3600

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, signing_ttl: DEFAULT_SIGNING_TTL) ⇒ Memory

Returns a new instance of Memory.



80
81
82
83
84
85
# File 'lib/hls/storage.rb', line 80

def initialize(name:, signing_ttl: DEFAULT_SIGNING_TTL)
  @name = name
  @signing_ttl = signing_ttl
  @store = {}
  @mutex = Mutex.new
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



77
78
79
# File 'lib/hls/storage.rb', line 77

def name
  @name
end

#signing_ttlObject

Returns the value of attribute signing_ttl.



78
79
80
# File 'lib/hls/storage.rb', line 78

def signing_ttl
  @signing_ttl
end

Class Method Details

.build(name: "memory", signing_ttl: DEFAULT_SIGNING_TTL, objects: {}) ⇒ Object



71
72
73
74
75
# File 'lib/hls/storage.rb', line 71

def self.build(name: "memory", signing_ttl: DEFAULT_SIGNING_TTL, objects: {})
  bucket = new(name: name, signing_ttl: signing_ttl)
  objects.each { |key, body| bucket.object(key).put(body: body) }
  bucket
end

Instance Method Details

#keysObject



91
92
93
# File 'lib/hls/storage.rb', line 91

def keys
  @mutex.synchronize { @store.keys }
end

#object(key) ⇒ Object



87
88
89
# File 'lib/hls/storage.rb', line 87

def object(key)
  Object.new(store: @store, mutex: @mutex, key: key, signing_ttl: @signing_ttl)
end