Class: S3Ranger::Config
- Inherits:
-
Hash
- Object
- Hash
- S3Ranger::Config
- Defined in:
- lib/s3ranger/config.rb
Constant Summary collapse
- REQUIRED_VARS =
[:AWS_ACCESS_KEY_ID, :AWS_SECRET_ACCESS_KEY]
- CONFIG_PATHS =
["#{ENV['S3RANGER_PATH']}", "#{ENV['HOME']}/.s3ranger.yml", "/etc/s3ranger.yml"]
Instance Method Summary collapse
Instance Method Details
#read ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# 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 ⇒ Object
75 76 77 78 79 |
# 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 ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# 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 |