-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from gingermusketeer/add-settings-checks
Add settings checks
- Loading branch information
Showing
9 changed files
with
137 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Rufo::Settings | ||
OPTIONS = { | ||
spaces_around_binary: [:dynamic, :one], | ||
parens_in_def: [:yes, :dynamic], | ||
double_newline_inside_type: [:dynamic, :no], | ||
align_case_when: [false, true], | ||
align_chained_calls: [false, true], | ||
trailing_commas: [:always, :never], | ||
} | ||
|
||
attr_accessor *OPTIONS.keys | ||
|
||
def init_settings(options) | ||
OPTIONS.each do |name, valid_options| | ||
default = valid_options.first | ||
value = options.fetch(name, default) | ||
unless valid_options.include?(value) | ||
$stderr.puts "Invalid value for #{name}: #{value.inspect}. Valid " \ | ||
"values are: #{valid_options.map(&:inspect).join(', ')}" | ||
value = default | ||
end | ||
self.public_send("#{name}=", value) | ||
end | ||
diff = options.keys - OPTIONS.keys | ||
diff.each do |key| | ||
$stderr.puts "Invalid config option=#{key}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe Rufo::DotFile do | ||
describe '#parse' do | ||
it 'parses booleans' do | ||
expect(subject.parse("key true\nother false")).to eql( | ||
key: true, | ||
other: false, | ||
) | ||
end | ||
|
||
it 'parses symbols' do | ||
expect(subject.parse("key :true")).to eql( | ||
key: :true, | ||
) | ||
end | ||
|
||
it 'warns about config it cannot parse' do | ||
result = nil | ||
expect { | ||
result = subject.parse("key 1") | ||
}.to output(%(Unknown config value="1" for "key"\n)).to_stderr | ||
|
||
expect(result).to eql({}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe Rufo::Settings do | ||
class TestClass | ||
include Rufo::Settings | ||
end | ||
|
||
subject { TestClass.new } | ||
|
||
describe 'settings' do | ||
it 'does not output any warnings for expected settings' do | ||
expect { | ||
subject.init_settings(spaces_around_binary: :dynamic) | ||
}.to output('').to_stderr | ||
end | ||
|
||
it 'outputs a warning for invalid config value' do | ||
exp_msg = "Invalid value for spaces_around_binary: :fake. Valid values " \ | ||
"are: :dynamic, :one\n" | ||
expect { | ||
subject.init_settings(spaces_around_binary: :fake) | ||
}.to output(exp_msg).to_stderr | ||
end | ||
|
||
it 'outputs a warning for invalid config option' do | ||
exp_msg = "Invalid config option=fake\n" | ||
expect { | ||
subject.init_settings(fake: :fake_too) | ||
}.to output(exp_msg).to_stderr | ||
end | ||
end | ||
end |