Class: SharedTools::Tools::Disk::LocalDriver

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

Overview

A driver for interacting with a disk via various operations

Instance Method Summary collapse

Methods inherited from BaseDriver

#directroy_delete, #initialize

Constructor Details

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

Instance Method Details

#directory_create(path:) ⇒ Object

Parameters:

Raises:



13
14
15
# File 'lib/shared_tools/tools/disk/local_driver.rb', line 13

def directory_create(path:)
  FileUtils.mkdir_p(resolve!(path:))
end

#directory_delete(path:) ⇒ Object

Parameters:



18
19
20
# File 'lib/shared_tools/tools/disk/local_driver.rb', line 18

def directory_delete(path:)
  FileUtils.rmdir(resolve!(path:))
end

#directory_list(path: ".") ⇒ Object

Parameters:

  • (defaults to: ".")

    optional



23
24
25
26
27
# File 'lib/shared_tools/tools/disk/local_driver.rb', line 23

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:



31
32
33
# File 'lib/shared_tools/tools/disk/local_driver.rb', line 31

def directory_move(path:, destination:)
  FileUtils.mv(resolve!(path:), resolve!(path: destination))
end

#file_create(path:) ⇒ Object

Parameters:



36
37
38
39
# File 'lib/shared_tools/tools/disk/local_driver.rb', line 36

def file_create(path:)
  path = resolve!(path:)
  FileUtils.touch(path) unless File.exist?(path)
end

#file_delete(path:) ⇒ Object

Parameters:



42
43
44
# File 'lib/shared_tools/tools/disk/local_driver.rb', line 42

def file_delete(path:)
  File.delete(resolve!(path:))
end

#file_move(path:, destination:) ⇒ Object

Parameters:



48
49
50
# File 'lib/shared_tools/tools/disk/local_driver.rb', line 48

def file_move(path:, destination:)
  FileUtils.mv(resolve!(path:), resolve!(path: destination))
end

#file_read(path:) ⇒ String

Parameters:

Returns:



55
56
57
# File 'lib/shared_tools/tools/disk/local_driver.rb', line 55

def file_read(path:)
  File.read(resolve!(path:))
end

#file_replace(old_text:, new_text:, path:) ⇒ Object

Parameters:



62
63
64
65
66
67
# File 'lib/shared_tools/tools/disk/local_driver.rb', line 62

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:



71
72
73
# File 'lib/shared_tools/tools/disk/local_driver.rb', line 71

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