forked from standardrb/lint_roller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support module for plugin authors
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module LintRoller | ||
module Support | ||
class MergesUpstreamMetadata | ||
def merge(plugin_yaml, upstream_yaml) | ||
common_upstream_values = upstream_yaml.select { |key| plugin_yaml.key?(key) } | ||
|
||
plugin_yaml.merge(common_upstream_values) { |key, plugin_value, upstream_value| | ||
if plugin_value.is_a?(Hash) && upstream_value.is_a?(Hash) | ||
plugin_value.merge(upstream_value) { |sub_key, plugin_sub_value, upstream_sub_value| | ||
if plugin_value.key?(sub_key) | ||
plugin_sub_value | ||
else | ||
upstream_sub_value | ||
end | ||
} | ||
else | ||
plugin_value | ||
end | ||
} | ||
end | ||
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,67 @@ | ||
require "test_helper" | ||
|
||
module LintRoller | ||
module Support | ||
class MergesUpstreamMetadataTest < Minitest::Test | ||
def setup | ||
@subject = MergesUpstreamMetadata.new | ||
end | ||
|
||
def test_no_op | ||
assert_equal({}, @subject.merge({}, {})) | ||
assert_equal({}, @subject.merge({}, {:junk => {}, "Some/Rule" => {}})) | ||
assert_equal({foo: "berry"}, @subject.merge({foo: "berry"}, {:junk => {}, "Some/Rule" => {}})) | ||
end | ||
|
||
def test_merges_undefined_sub_keys | ||
assert_equal( | ||
{"Some/Rule" => {"Enabled" => true, "Description" => "foo"}}, | ||
@subject.merge( | ||
{"Some/Rule" => {"Enabled" => true}}, | ||
{"Some/Rule" => {"Description" => "foo"}} | ||
) | ||
) | ||
end | ||
|
||
def test_doesnt_merge_nil_values | ||
assert_equal( | ||
{"Some/Rule" => {"Description" => nil}}, | ||
@subject.merge( | ||
{"Some/Rule" => {"Description" => nil}}, | ||
{"Some/Rule" => {"Description" => "foo"}} | ||
) | ||
) | ||
end | ||
|
||
def test_doesnt_override_defined_values | ||
assert_equal( | ||
{"Some/Rule" => {"Enabled" => false}}, | ||
@subject.merge( | ||
{"Some/Rule" => {"Enabled" => false}}, | ||
{"Some/Rule" => {"Enabled" => true}} | ||
) | ||
) | ||
end | ||
|
||
def test_doesnt_munge_arrays | ||
assert_equal( | ||
{"Some/Rule" => {"Included" => ["lol"]}}, | ||
@subject.merge( | ||
{"Some/Rule" => {"Included" => ["lol"]}}, | ||
{"Some/Rule" => {"Included" => ["kek"]}} | ||
) | ||
) | ||
end | ||
|
||
def test_doesnt_munge_hashes | ||
assert_equal( | ||
{"Some/Rule" => {"Conf" => {a: 1}}}, | ||
@subject.merge( | ||
{"Some/Rule" => {"Conf" => {a: 1}}}, | ||
{"Some/Rule" => {"Conf" => {a: 2, b: 3}}} | ||
) | ||
) | ||
end | ||
end | ||
end | ||
end |