Class: DeepAgents::FileSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/deepagents/tools.rb

Overview

FileSystem class for managing virtual files

Instance Method Summary collapse

Constructor Details

#initialize(initial_files = {}) ⇒ FileSystem



68
69
70
# File 'lib/deepagents/tools.rb', line 68

def initialize(initial_files = {})
  @files = initial_files
end

Instance Method Details

#delete(path) ⇒ Object

Raises:



82
83
84
85
# File 'lib/deepagents/tools.rb', line 82

def delete(path)
  raise FileNotFoundError.new(path) unless @files.key?(path)
  @files.delete(path)
end

#exists?(path) ⇒ Boolean



91
92
93
# File 'lib/deepagents/tools.rb', line 91

def exists?(path)
  @files.key?(path)
end

#listObject



87
88
89
# File 'lib/deepagents/tools.rb', line 87

def list
  @files.keys
end

#read(path) ⇒ Object

Raises:



72
73
74
75
76
# File 'lib/deepagents/tools.rb', line 72

def read(path)
  file = @files[path]
  raise FileNotFoundError.new(path) unless file
  file
end

#to_hObject



95
96
97
# File 'lib/deepagents/tools.rb', line 95

def to_h
  @files
end

#write(path, content) ⇒ Object



78
79
80
# File 'lib/deepagents/tools.rb', line 78

def write(path, content)
  @files[path] = content
end