Class: OPA::Archive
- Inherits:
-
Object
- Object
- OPA::Archive
- Defined in:
- lib/opa/archive.rb
Overview
Builds OPA archive (.opa) files. An OPA archive is a ZIP file containing a manifest, prompt file, and optional session history and data assets.
Instance Attribute Summary collapse
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
Instance Method Summary collapse
- #add_data(path, content) ⇒ Object
- #add_entry(path, content) ⇒ Object
- #add_session(content) ⇒ Object
-
#initialize ⇒ Archive
constructor
A new instance of Archive.
- #prompt=(content) ⇒ Object
-
#sign(private_key, certificate, algorithm: "SHA-256") ⇒ Object
Sign the archive with a private key and certificate.
- #write(io_or_path) ⇒ Object
Constructor Details
#initialize ⇒ Archive
Returns a new instance of Archive.
12 13 14 15 |
# File 'lib/opa/archive.rb', line 12 def initialize @manifest = Manifest.new @entries = {} # path => content (String or IO) end |
Instance Attribute Details
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
10 11 12 |
# File 'lib/opa/archive.rb', line 10 def manifest @manifest end |
Instance Method Details
#add_data(path, content) ⇒ Object
22 23 24 25 |
# File 'lib/opa/archive.rb', line 22 def add_data(path, content) full_path = "data/#{path}" @entries[full_path] = content end |
#add_entry(path, content) ⇒ Object
32 33 34 |
# File 'lib/opa/archive.rb', line 32 def add_entry(path, content) @entries[path] = content end |
#add_session(content) ⇒ Object
27 28 29 30 |
# File 'lib/opa/archive.rb', line 27 def add_session(content) session_path = @manifest["Session-File"] || "session/history.json" @entries[session_path] = content end |
#prompt=(content) ⇒ Object
17 18 19 20 |
# File 'lib/opa/archive.rb', line 17 def prompt=(content) prompt_path = @manifest["Prompt-File"] || "prompt.md" @entries[prompt_path] = content end |
#sign(private_key, certificate, algorithm: "SHA-256") ⇒ Object
Sign the archive with a private key and certificate. Must be called before #write.
38 39 40 |
# File 'lib/opa/archive.rb', line 38 def sign(private_key, certificate, algorithm: "SHA-256") @signer = Signer.new(private_key, certificate, algorithm: algorithm) end |
#write(io_or_path) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/opa/archive.rb', line 42 def write(io_or_path) if io_or_path.is_a?(String) File.open(io_or_path, "wb") { |f| write_to_stream(f) } else write_to_stream(io_or_path) end end |