Class: RubyLLM::Models::Registry::FileStore

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/models/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileStore

Returns a new instance of FileStore.

Raises:



16
17
18
19
# File 'lib/ruby_llm/models/registry.rb', line 16

def initialize(path)
  @path = path.respond_to?(:path) ? path.path : path.to_s
  raise ModelRegistryError, 'A model registry file path is required' if @path.empty?
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/ruby_llm/models/registry.rb', line 14

def path
  @path
end

Instance Method Details

#etagObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/ruby_llm/models/registry.rb', line 25

def etag
  return unless File.file?(path)

  value = File.read(etag_path).strip
  value unless value.empty?
rescue Errno::ENOENT
  nil
rescue SystemCallError => e
  raise ModelRegistryError, "Could not read the model registry ETag from #{etag_path}: #{e.message}"
end

#readObject



21
22
23
# File 'lib/ruby_llm/models/registry.rb', line 21

def read
  Registry.read(path)
end

#write(models, etag: nil) ⇒ Object



36
37
38
39
40
41
# File 'lib/ruby_llm/models/registry.rb', line 36

def write(models, etag: nil)
  FileUtils.mkdir_p(File.dirname(path))
  atomic_write(path, Registry.pretty_json(models))
  write_etag(etag)
  models
end