Skip to content

Commit

Permalink
Merge pull request #390 from BBC-News/better_config_file_locating
Browse files Browse the repository at this point in the history
better config file locating
  • Loading branch information
ChrisBAshton committed Feb 28, 2016
2 parents 7b70901 + 0856cec commit 4c0c3c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/wraith/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def copy_old_shots(config_name)
desc "validate", "checks your configuration and validates that all required properties exist"
def validate(config_name)
within_acceptable_limits do
Wraith::Validate.new(config_name).validate
logger.info Wraith::Validate.new(config_name).validate
end
end

Expand Down
22 changes: 15 additions & 7 deletions lib/wraith/wraith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@ class Wraith::Wraith
def initialize(config, yaml_passed = false)
@config = yaml_passed ? config : open_config_file(config)
logger.level = verbose ? Logger::DEBUG : Logger::INFO
rescue
logger.error "unable to find config at #{config}"
end

def open_config_file(config_name)
if File.exist?(config_name) && File.extname(config_name) == ".yaml"
config = File.open config_name
else
config = File.open "configs/#{config_name}.yaml"
possible_filenames = [
config_name,
"#{config_name}.yml",
"#{config_name}.yaml",
"configs/#{config_name}.yml",
"configs/#{config_name}.yaml"
]

possible_filenames.each do |filepath|
if File.exist?(filepath)
config = File.open config_name
return YAML.load config
end
end
YAML.load config
rescue
logger.error "unable to find config \"#{config}\""
end

def directory
Expand Down

0 comments on commit 4c0c3c0

Please sign in to comment.