Class: DevSystem::FileShell

Inherits:
Shell show all
Defined in:
lib/dev_system/sub/shell/shells/file_shell.rb

Direct Known Subclasses

BinShell, DirShell, TextFileShell, TextShell

Class Method Summary collapse

Methods inherited from Shell

all, cruby?, engine, jruby?, linux?, mac?, os, ruby_version, unix?, windows?

Methods inherited from Liza::Controller

color, inherited, on_connected

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Class Method Details

._raise_if_blank(path) ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 3

def self._raise_if_blank path
  raise ArgumentError, "Path is required" if path.nil? || path.to_s.empty?
end

._raise_if_not_exists(path, log_level: self.log_level) ⇒ Object

Raises:

  • (ArgumentError)


7
8
9
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 7

def self._raise_if_not_exists path, log_level: self.log_level
  raise ArgumentError, "File does not exist at '#{path}'" unless exist?(path, log_level: log_level)
end

.category_for(path, log_level: self.log_level) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 50

def self.category_for path, log_level: self.log_level
  log log_level, "Getting category for '#{path}'"
  _raise_if_blank path

  return :directory     if directory?     path, log_level: :lowest
  return :file          if file?          path, log_level: :lowest
  return :symbolic_link if symbolic_link? path, log_level: :lowest
end

.directory?(path, log_level: self.log_level) ⇒ Boolean

category

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 29

def self.directory? path, log_level: self.log_level
  log log_level, "Checking if '#{path}' is a directory"
  _raise_if_blank path

  File.directory? path
end

.exist?(path, log_level: self.log_level) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 13

def self.exist? path, log_level: self.log_level
  log log_level, "Checking if file exists at '#{path}'"
  _raise_if_blank path

  File.exist? path
end

.file?(path, log_level: self.log_level) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 36

def self.file? path, log_level: self.log_level
  log log_level, "Checking if '#{path}' is a file"
  _raise_if_blank path

  File.file? path
end

.gitkeep(path) ⇒ Object



71
72
73
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 71

def self.gitkeep path
  touch "#{path}/.gitkeep"
end

.size(path, log_level: self.log_level) ⇒ Object



20
21
22
23
24
25
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 20

def self.size path, log_level: self.log_level
  log log_level, "Getting size of file at '#{path}'"
  _raise_if_not_exists path

  File.size path
end

.symbolic_link?(path, log_level: self.log_level) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 43

def self.symbolic_link? path, log_level: self.log_level
  log log_level, "Checking if '#{path}' is a symbolic link"
  _raise_if_blank path

  File.symlink? path
end

.touch(path, log_level: self.log_level) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 61

def self.touch path, log_level: self.log_level
  log log_level, "Touching '#{path}'"
  _raise_if_blank path

  dir = File.dirname(path)
  DevSystem::DirShell.create dir

  FileUtils.touch path
end