Class: S3Ranger::Config

Inherits:
Hash
  • Object
show all
Defined in:
lib/s3ranger/config.rb

Instance Method Summary collapse

Instance Method Details

#readObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/s3ranger/config.rb', line 18

def read
  paths_checked = []

  ["#{ENV['S3CONF']}", "#{ENV['HOME']}/.s3conf", "/etc/s3conf"].each do |path|

    # Filtering some garbage
    next if path.nil? or path.strip.empty?

    # Feeding the user feedback in case of failure
    paths_checked << path

    # Time for the dirty work, let's parse the config file and feed our
    # internal hash
    if File.exists?("#{path}/s3config.yml")
      config = YAML.load_file("#{path}/s3config.yml")
      config.each_pair do |key, value|
        self[key.upcase.to_sym] = value
      end
      return
    end
  end

  raise NoConfigFound.new paths_checked
end