Method: Confinicky::ShellFile#initialize

Defined in:
lib/confinicky/shell_file.rb

#initialize(file_path: "") ⇒ ShellFile

Parses the configuration file if it exists.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/confinicky/shell_file.rb', line 28

def initialize(file_path: "")
  raise "Config file not found. Please set" if !File.exists?(@file_path = file_path)
  @exports = []
  @aliases = []
  @lines = []

  file = File.new(@file_path, "r")
  command = nil

  while (line = file.gets)
    if !command.nil? && command.open?
      command.append line
    else
      command = Confinicky::Parsers::Command.new(line: line)
    end

    @lines << line if command.line?
    @exports << command.values_array if command.export? and command.closed?
    @aliases << command.values_array if command.alias? and command.closed?
  end

  file.close()
end