Class: OmniAI::Tools::Disk::LocalDriver

Inherits:
BaseDriver
  • Object
show all
Defined in:
lib/omniai/tools/disk/local_driver.rb

Overview

A driver for interacting with a disk via various operations

Instance Method Summary collapse

Methods inherited from BaseDriver

#initialize

Constructor Details

This class inherits a constructor from OmniAI::Tools::Disk::BaseDriver

Instance Method Details

#directory_create(path:) ⇒ Object

Parameters:

  • path (String)

Raises:

  • (SecurityError)


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

Parameters:

  • path (String) (defaults to: ".")

    optional



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

Parameters:

  • path (String)
  • destination (String)


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

Parameters:

  • path (String)


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

Parameters:

  • path (String)


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

Parameters:

  • path (String)


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

Parameters:

  • path (String)
  • destination (String)


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

Parameters:

  • path (String)

Returns:

  • (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

Parameters:

  • old_text (String)
  • new_text (String)
  • path (String)


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

Parameters:

  • path (String)
  • text (String)


69
70
71
# File 'lib/omniai/tools/disk/local_driver.rb', line 69

def file_write(path:, text:)
  File.write(resolve!(path:), text)
end