Class: OmniAI::Tools::Disk::LocalDriver
Overview
A driver for interacting with a disk via various operations
Instance Method Summary
collapse
Methods inherited from BaseDriver
#initialize
Instance Method Details
#directory_create(path:) ⇒ Object
11
12
13
|
# File 'lib/omniai/tools/disk/local_driver.rb', line 11
def directory_create(path:)
FileUtils.mkdir_p(resolve!(path:))
end
|
#directory_list(path: ".") ⇒ Object
21
22
23
24
25
|
# File 'lib/omniai/tools/disk/local_driver.rb', line 21
def directory_list(path: ".")
Dir.chdir(resolve!(path:)) do
Dir.glob("**/*").map { |path| summarize(path:) }.join("\n")
end
end
|
#directory_move(path:, destination:) ⇒ Object
29
30
31
|
# File 'lib/omniai/tools/disk/local_driver.rb', line 29
def directory_move(path:, destination:)
FileUtils.mv(resolve!(path:), resolve!(path: destination))
end
|
#directroy_delete(path:) ⇒ Object
16
17
18
|
# File 'lib/omniai/tools/disk/local_driver.rb', line 16
def directroy_delete(path:)
FileUtils.rmdir(resolve!(path:))
end
|
#file_create(path:) ⇒ Object
34
35
36
37
|
# File 'lib/omniai/tools/disk/local_driver.rb', line 34
def file_create(path:)
path = resolve!(path:)
FileUtils.touch(path) unless File.exist?(path)
end
|
#file_delete(path:) ⇒ Object
40
41
42
|
# File 'lib/omniai/tools/disk/local_driver.rb', line 40
def file_delete(path:)
File.delete(resolve!(path:))
end
|
#file_move(path:, destination:) ⇒ Object
46
47
48
|
# File 'lib/omniai/tools/disk/local_driver.rb', line 46
def file_move(path:, destination:)
FileUtils.mv(resolve!(path:), resolve!(path: destination))
end
|
#file_read(path:) ⇒ String
53
54
55
|
# File 'lib/omniai/tools/disk/local_driver.rb', line 53
def file_read(path:)
File.read(resolve!(path:))
end
|
#file_replace(old_text:, new_text:, path:) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/omniai/tools/disk/local_driver.rb', line 60
def file_replace(old_text:, new_text:, path:)
path = resolve!(path:)
contents = File.read(path)
text = contents.gsub(old_text, new_text)
File.write(path, text)
end
|
#file_write(path:, text:) ⇒ Object
69
70
71
|
# File 'lib/omniai/tools/disk/local_driver.rb', line 69
def file_write(path:, text:)
File.write(resolve!(path:), text)
end
|