Class: Smith::Artifacts::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/artifacts/memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace: nil) ⇒ Memory

Returns a new instance of Memory.



10
11
12
13
14
# File 'lib/smith/artifacts/memory.rb', line 10

def initialize(namespace: nil)
  @namespace = namespace
  @store = {}
  @metadata = {}
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



8
9
10
# File 'lib/smith/artifacts/memory.rb', line 8

def namespace
  @namespace
end

Instance Method Details

#expired(retention: nil, execution_namespace: nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/smith/artifacts/memory.rb', line 32

def expired(retention: nil, execution_namespace: nil)
  effective_retention = retention || Smith.config.artifact_retention
  return [] unless effective_retention

  cutoff = Time.now.utc - effective_retention
  @metadata.select { |ref, meta| expired_match?(ref, meta, cutoff, execution_namespace) }.keys
end

#fetch(ref) ⇒ Object



25
26
27
28
29
30
# File 'lib/smith/artifacts/memory.rb', line 25

def fetch(ref)
  enforce_tenant_isolation!
  return nil unless owns_ref?(ref)

  @store[ref]
end

#store(data, content_type: "application/octet-stream", execution_namespace: nil) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/smith/artifacts/memory.rb', line 16

def store(data, content_type: "application/octet-stream", execution_namespace: nil)
  enforce_tenant_isolation!
  ref = generate_ref(data)
  @store[ref] = data
  @metadata[ref] ||= { content_type: content_type, stored_at: Time.now.utc, execution_namespaces: [] }
  tag_execution_namespace(ref, execution_namespace)
  ref
end