Method: Core::Config#load

Defined in:
lib/config.rb

#load(file = Core::DEFAULT_CONFIG) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/config.rb', line 19

def load(file=Core::DEFAULT_CONFIG)
  if !File.exists?(Core::HOME_PATH + file)
    File.new(Core::HOME_PATH + file, "w")
  else
    if File.size(Core::HOME_PATH + file) > 0
      begin
        @hash = Marshal.load(File.open(Core::HOME_PATH + file, "r"))
        validate
      rescue TypeError
        puts("WARNING: Corrupted config file (#{file}), reverting to default")
      rescue NoMethodError # this is likely caused by outdated configs
          warn("WARNING: Config file #{file} is outdated, deleting")
          File.delete(Core::HOME_PATH + file)
      end
    end
  end
end