Class: Smith::Artifacts::Memory
- Inherits:
-
Object
- Object
- Smith::Artifacts::Memory
- Defined in:
- lib/smith/artifacts/memory.rb
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #expired(retention: nil, execution_namespace: nil) ⇒ Object
- #fetch(ref) ⇒ Object
-
#initialize(namespace: nil) ⇒ Memory
constructor
A new instance of Memory.
- #store(data, content_type: "application/octet-stream", execution_namespace: nil) ⇒ Object
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
#namespace ⇒ Object (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, | expired_match?(ref, , 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 |