-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow whitelist configurations to be loaded from database
- Loading branch information
Showing
8 changed files
with
155 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module PactBroker | ||
module Config | ||
class SpaceDelimitedStringList < Array | ||
|
||
def initialize list | ||
super(list) | ||
end | ||
|
||
def self.parse(string) | ||
array = (string || '').split(' ').collect do | word | | ||
if word[0] == '/' and word[-1] == '/' | ||
Regexp.new(word[1..-2]) | ||
else | ||
word | ||
end | ||
end | ||
SpaceDelimitedStringList.new(array) | ||
end | ||
|
||
def to_s | ||
collect do | word | | ||
if word.is_a?(Regexp) | ||
"/#{word.source}/" | ||
else | ||
word | ||
end | ||
end.join(' ') | ||
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
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
45 changes: 45 additions & 0 deletions
45
spec/lib/pact_broker/config/space_delimited_string_list_spec.rb
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,45 @@ | ||
require 'pact_broker/config/space_delimited_string_list' | ||
|
||
module PactBroker | ||
module Config | ||
describe SpaceDelimitedStringList do | ||
describe "parse" do | ||
subject { SpaceDelimitedStringList.parse(input) } | ||
|
||
context "when input is ''" do | ||
let(:input) { "" } | ||
|
||
it { is_expected.to eq [] } | ||
|
||
its(:to_s) { is_expected.to eq input } | ||
end | ||
|
||
context "when input is 'foo bar'" do | ||
let(:input) { "foo bar" } | ||
|
||
it { is_expected.to eq ["foo", "bar"] } | ||
|
||
it { is_expected.to be_a SpaceDelimitedStringList } | ||
|
||
its(:to_s) { is_expected.to eq input } | ||
end | ||
|
||
context "when input is '/foo.*/'" do | ||
let(:input) { "/foo.*/" } | ||
|
||
it { is_expected.to eq [/foo.*/] } | ||
|
||
its(:to_s) { is_expected.to eq input } | ||
end | ||
|
||
context "when input is '/foo\\.*/' (note double backslash)" do | ||
let(:input) { "/foo\\.*/" } | ||
|
||
it { is_expected.to eq [/foo\.*/] } | ||
|
||
its(:to_s) { is_expected.to eq input } | ||
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