Class: ToolsFiles

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/lib/files.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ToolsFiles

Returns a new instance of ToolsFiles.



5
6
# File 'lib/lib/files.rb', line 5

def initialize(options = {})
end

Class Method Details

.create_dir(directory, directory_name) ⇒ Object

Create a directory in work area

Sample ToolsFiles.create_dir Tools.home + '/2018/xykotools/tools/home', 'tools_home' home = (ToolsUtil.get_variable 'tools_home') => ~/2018/xykotools/tools/home

Parameters:

  • directory
  • directory_name

Returns:



18
19
20
21
22
23
24
25
26
27
# File 'lib/lib/files.rb', line 18

def self.create_dir directory, directory_name
  unless directory.end_with? '/'
    directory += '/'
  end
  complete_file = (directory + '/').gsub('//','/')
  unless File.exists? complete_file
    Dir.mkdir(complete_file)
  end
  ToolsUtil.set_variable directory_name, complete_file
end

.create_file(directory, file_name, file_name_set) ⇒ Object

Create a file in work area

Sample

ToolsFiles.create_file home, 'xyko_file.txt', 'xyko_file' xyko = (ToolsUtil.get_variable 'xyko_file') => ~/2018/xykotools/tools/home/xyko_file.txt

Parameters:

  • directory
  • file_name
  • file_name_set

Returns:



40
41
42
43
44
45
46
# File 'lib/lib/files.rb', line 40

def self.create_file directory, file_name, file_name_set
  complete_file = (directory + '/' + file_name).gsub('//','/')
  unless File.exists? complete_file
    file = File.open( complete_file , 'w')
  end
  ToolsUtil.set_variable file_name_set, complete_file
end

.load_file(file_to_load) ⇒ Object

Load a file in work area

Sample

ToolsFiles.load_file file_to_load

Parameters:

  • file_to_load —

    Object

Returns:



55
56
57
58
59
60
# File 'lib/lib/files.rb', line 55

def self.load_file file_to_load
  if File.exists? file_to_load
    file = File.open( file_to_load , 'r')
    return file
  end
end

.open_file(file, default_editor = nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/lib/files.rb', line 62

def self.open_file file, default_editor=nil
  begin
    if default_editor.nil?
      TTY::Editor.open( file, command: :vi)
    else
      TTY::Editor.open( file, command: default_editor)
    end
  rescue Exception => e
    return e
  end
end