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

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

.directory?(path) ⇒ Boolean

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 :normal, "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) ⇒ 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 :normal, "Checking if '#{path}' is a file"
  _raise_if_blank path

  File.file? path
end

.gitkeep(path) ⇒ Object



55
56
57
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 55

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

.size(path) ⇒ Object



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

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

  File.size path
end

.touch(path) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/dev_system/sub/shell/shells/file_shell.rb', line 45

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

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

  FileUtils.touch path
end