Skip to content

Commit

Permalink
Merge pull request #248 from samvera/247-config-error
Browse files Browse the repository at this point in the history
BrowseEverything::ConfigurationError for missing configuration yml
  • Loading branch information
jrgriffiniii committed Nov 16, 2018
2 parents 9e4be83 + 3de4efd commit 4e731ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/browse_everything.rb
Expand Up @@ -40,6 +40,7 @@ module Google
end

class InitializationError < RuntimeError; end
class ConfigurationError < StandardError; end
class NotImplementedError < StandardError; end
class NotAuthorizedError < StandardError; end

Expand All @@ -51,11 +52,15 @@ def configure(value)
if value.is_a?(Hash)
@config = ActiveSupport::HashWithIndifferentAccess.new value
elsif value.is_a?(String)
config_file_content = File.read(value)
config_file_template = ERB.new(config_file_content)
config_values = YAML.safe_load(config_file_template.result, [Symbol])
@config = ActiveSupport::HashWithIndifferentAccess.new config_values
@config.deep_symbolize_keys
begin
config_file_content = File.read(value)
config_file_template = ERB.new(config_file_content)
config_values = YAML.safe_load(config_file_template.result, [Symbol])
@config = ActiveSupport::HashWithIndifferentAccess.new config_values
@config.deep_symbolize_keys
rescue Errno::ENOENT
raise ConfigurationError, 'Missing browse_everything_providers.yml configuration file'
end
else
raise InitializationError, "Unrecognized configuration: #{value.inspect}"
end
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/browse_everything_spec.rb
Expand Up @@ -72,6 +72,13 @@

it_behaves_like 'a configured BrowseEverything module'
end

context 'without a YAML file' do
let(:config) { '' }
it 'raises a configuration error' do
expect { described_class.configure(:config).to raise_error(BrowseEverything::ConfigurationError, 'Missing browse_everything_providers.yml configuration file') }
end
end
end

context 'with an unsupported or invalid configuration' do
Expand Down

0 comments on commit 4e731ce

Please sign in to comment.