Warn on conf when an option is not recognized
parent
47b5f569a4
commit
7126afbc9c
|
|
@ -5,6 +5,7 @@ Squib follows [semantic versioning](http://semver.org).
|
||||||
|
|
||||||
Chores:
|
Chores:
|
||||||
* Ripped out a lot of old constants used from the old way we handled arguments. Yay negative churn!
|
* Ripped out a lot of old constants used from the old way we handled arguments. Yay negative churn!
|
||||||
|
* Emit a warning when a `config.yml` option is not recognized
|
||||||
|
|
||||||
## v0.8.0 / 2015-10-26
|
## v0.8.0 / 2015-10-26
|
||||||
Features
|
Features
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ module Squib
|
||||||
Squib::logger.info { " using config: #{file}" }
|
Squib::logger.info { " using config: #{file}" }
|
||||||
yaml = YAML.load_file(file) || {}
|
yaml = YAML.load_file(file) || {}
|
||||||
end
|
end
|
||||||
|
warn_unrecognized(yaml)
|
||||||
Conf.new(DEFAULTS.merge(yaml))
|
Conf.new(DEFAULTS.merge(yaml))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -113,5 +114,13 @@ module Squib
|
||||||
@config_hash['antialias'] = ANTIALIAS_OPTS[@config_hash['antialias'].downcase.strip]
|
@config_hash['antialias'] = ANTIALIAS_OPTS[@config_hash['antialias'].downcase.strip]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Were there any unrecognized options in the config file?
|
||||||
|
def self.warn_unrecognized(yaml)
|
||||||
|
unrec = yaml.keys - DEFAULTS.keys
|
||||||
|
if unrec.any?
|
||||||
|
Squib::logger.warn "Unrecognized configuration option(s): #{unrec.join(',')}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,17 @@ require 'spec_helper'
|
||||||
describe Squib::Conf do
|
describe Squib::Conf do
|
||||||
|
|
||||||
it 'parses the project template file just fine' do
|
it 'parses the project template file just fine' do
|
||||||
conf = Squib::Conf.load(project_template('config.yml'))
|
conf = Squib::Conf.load project_template('config.yml')
|
||||||
expect(conf.backend).to eq(Squib::Conf::DEFAULTS['backend'])
|
expect(conf.backend).to eq(Squib::Conf::DEFAULTS['backend'])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses an empty file' do
|
it 'parses an empty file' do
|
||||||
conf = Squib::Conf.load(conf('empty.yml'))
|
conf = Squib::Conf.load conf('empty.yml')
|
||||||
expect(conf.backend).to eq(Squib::Conf::DEFAULTS['backend'])
|
expect(conf.backend).to eq(Squib::Conf::DEFAULTS['backend'])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses the sample custom config' do
|
it 'parses the sample custom config' do
|
||||||
conf = Squib::Conf.load(sample_file('custom-config.yml'))
|
conf = Squib::Conf.load sample_file('custom-config.yml')
|
||||||
expect(conf.progress_bars).to be true
|
expect(conf.progress_bars).to be true
|
||||||
expect(conf.text_hint).to eq '#FF0000'
|
expect(conf.text_hint).to eq '#FF0000'
|
||||||
expect(conf.custom_colors).to eq({ 'foo' => '#ccc' })
|
expect(conf.custom_colors).to eq({ 'foo' => '#ccc' })
|
||||||
|
|
@ -26,4 +26,9 @@ describe Squib::Conf do
|
||||||
expect(Squib::Conf.new.antialias).to eq 'subpixel'
|
expect(Squib::Conf.new.antialias).to eq 'subpixel'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'warns when the yml has an unrecognized option' do
|
||||||
|
expect(Squib::logger).to receive(:warn).with('Unrecognized configuration option(s): unicorns')
|
||||||
|
Squib::Conf.load conf('unrecognized.yml')
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
# This is recognized, so it should be fine.
|
||||||
|
backend: svg
|
||||||
|
# This is not recognized.
|
||||||
|
unicorns: true
|
||||||
Loading…
Reference in New Issue