Class: RubyLLM::Registry::FilesystemBackend
- Inherits:
-
Object
- Object
- RubyLLM::Registry::FilesystemBackend
- Defined in:
- lib/ruby_llm/registry/filesystem_backend.rb
Overview
Filesystem-backed registry adapter.
Constant Summary collapse
- SUPPORTED_EXTENSIONS =
%w[.md .prompt].freeze
Instance Method Summary collapse
- #available_versions(path) ⇒ Object
- #get(path, version: nil, label: nil) ⇒ Object
-
#initialize(root:, manifest_path: nil) ⇒ FilesystemBackend
constructor
A new instance of FilesystemBackend.
- #store(prompt, overwrite: false, extension: ".md") ⇒ Object
Constructor Details
#initialize(root:, manifest_path: nil) ⇒ FilesystemBackend
Returns a new instance of FilesystemBackend.
12 13 14 15 |
# File 'lib/ruby_llm/registry/filesystem_backend.rb', line 12 def initialize(root:, manifest_path: nil) @root = Pathname.new(root) @manifest_path = manifest_path && Pathname.new(manifest_path) end |
Instance Method Details
#available_versions(path) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/ruby_llm/registry/filesystem_backend.rb', line 31 def available_versions(path) prompt_dir = root.join(path) return [] unless prompt_dir.directory? prompt_dir.children.select { |entry| entry.file? && versioned_prompt_file?(entry) }.map do |entry| Version.parse(version_from_filename(entry.basename.to_s)) end.sort end |
#get(path, version: nil, label: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby_llm/registry/filesystem_backend.rb', line 17 def get(path, version: nil, label: nil) prompt_dir = root.join(path) raise PromptNotFoundError, "Prompt path not found: #{path}" unless prompt_dir.directory? manifest = load_manifest file_path = resolve_file_path(prompt_dir, path, version: version, label: label, manifest: manifest) if file_path.nil? raise PromptNotFoundError, "Prompt not found: #{path}#{lookup_suffix(version: version, label: label)}" end parse_prompt(path, file_path) end |
#store(prompt, overwrite: false, extension: ".md") ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby_llm/registry/filesystem_backend.rb', line 40 def store(prompt, overwrite: false, extension: ".md") prompt_dir = root.join(prompt.path) prompt_dir.mkpath target = prompt_dir.join("v#{prompt.version}#{extension}") raise Error, "Prompt already exists: #{target}" if target.exist? && !overwrite target.write(Exporter.new(prompt).to_markdown) prompt end |