class S3Ranger::Config

Constants

CONFIG_PATHS
REQUIRED_VARS

Public Instance Methods

read() click to toggle source
# File lib/s3ranger/config.rb, line 81
def read
  # Reading from file and then trying from env
  paths_checked = read_from_file
  read_from_env

  # Checking which variables we have
  not_found = []

  REQUIRED_VARS.each {|v|
    not_found << v if self[v].nil?
  }

  # Cleaning possibly empty env var from CONFIG_PATH
  paths = (paths_checked || CONFIG_PATHS).select {|e| !e.empty?}
  raise NoConfigFound.new(not_found, paths) if not_found.count > 0
end
read_from_env() click to toggle source
# File lib/s3ranger/config.rb, line 75
def read_from_env
  REQUIRED_VARS.each do |v|
    self[v] = ENV[v.to_s] unless ENV[v.to_s].nil?
  end
end
read_from_file() click to toggle source
# File lib/s3ranger/config.rb, line 50
def read_from_file
  paths_checked = []

  CONFIG_PATHS.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
      config = YAML.load_file path
      config.each_pair do |key, value|
        self[key.upcase.to_sym] = value
      end
      return 
    end
  end

  return paths_checked
end