Class: Krump::ConfigParser

Inherits:
Object
  • Object
show all
Defined in:
lib/krump/config_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename, environment) ⇒ ConfigParser

Returns a new instance of ConfigParser.



8
9
10
11
12
13
14
15
16
# File 'lib/krump/config_parser.rb', line 8

def initialize(filename, environment)
  @filename =
    if !filename.nil? && filename.start_with?('~/')
      "#{Dir.home}/#{filename.split('/', 2).last}"
    else
      filename
    end
  @environment = environment
end

Instance Method Details

#parseObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/krump/config_parser.rb', line 18

def parse
  if @filename && @environment
    File.open(@filename, 'r') { |fh| parse_config(fh.readlines) }
  else
    {}
  end
rescue Errno::ENOENT => e
  # Ignore file-not-found error if it's the default filename
  raise unless @filename == default_config
  {}
rescue StandardError => e
  STDERR.puts 'There is an error in your config file'
  raise
end