This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
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.
- Loading branch information
1 parent
ffa4f0b
commit 523cb08
Showing
5 changed files
with
72 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 @@ | ||
# frozen_string_literal: true | ||
|
||
module MOSAIK | ||
class Configuration | ||
attr_reader :include, :exclude | ||
|
||
def initialize(include = [], exclude = []) | ||
@include = include | ||
@exclude = exclude | ||
end | ||
|
||
def self.from(file) | ||
raise ConfigurationError, "Configuration file not found: #{file}" unless File.exist?(file) | ||
|
||
configuration = YAML.load_file(file) | ||
|
||
new( | ||
configuration["include"], | ||
configuration["exclude"], | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
# List of patterns for folder paths to include | ||
include: | ||
- foo | ||
- bar | ||
|
||
# List of patterns for folder paths to exclude | ||
exclude: | ||
- baz | ||
- qux |
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 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe MOSAIK::Configuration do | ||
subject(:configuration) { described_class.new } | ||
|
||
describe ".from" do | ||
context "when the configuration file exists" do | ||
let(:file) { "spec/fixtures/mosaik.yml" } | ||
|
||
it "creates a new configuration instance" do | ||
expect(described_class.from(file)).to be_a(described_class) | ||
end | ||
|
||
it "sets the include attribute" do | ||
expect(described_class.from(file).include).to eq(["foo", "bar"]) | ||
end | ||
|
||
it "sets the exclude attribute" do | ||
expect(described_class.from(file).exclude).to eq(["baz", "qux"]) | ||
end | ||
end | ||
|
||
context "when the configuration file does not exist" do | ||
let(:file) { "spec/fixtures/missing.yml" } | ||
|
||
it "raises an error" do | ||
expect { described_class.from(file) }.to raise_error(MOSAIK::ConfigurationError, "Configuration file not found: #{file}") | ||
end | ||
end | ||
end | ||
end |