Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make configuration persistence injectable
- Loading branch information
Matthew Kane Parker
committed
Sep 25, 2012
1 parent
2c3c170
commit be919cc
Showing
8 changed files
with
74 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,4 @@ | ||
module LicenseFinder | ||
class Configuration | ||
attr_reader :whitelist, :ignore_groups, :dependencies_dir | ||
|
||
def initialize | ||
config = {} | ||
|
||
if File.exists?(config_file_path) | ||
yaml = File.read(config_file_path) | ||
config = YAML.load(yaml) | ||
end | ||
|
||
@whitelist = config['whitelist'] || [] | ||
@ignore_groups = (config["ignore_groups"] || []).map(&:to_sym) | ||
@dependencies_dir = config['dependencies_file_dir'] || '.' | ||
end | ||
|
||
def config_file_path | ||
File.join('.', 'config', 'license_finder.yml') | ||
end | ||
|
||
def dependencies_yaml | ||
File.join(dependencies_dir, "dependencies.yml") | ||
end | ||
|
||
def dependencies_text | ||
File.join(dependencies_dir, "dependencies.txt") | ||
end | ||
|
||
def dependencies_html | ||
File.join(dependencies_dir, "dependencies.html") | ||
end | ||
class Configuration < LicenseFinder::Persistence::Configuration | ||
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
module LicenseFinder | ||
module Persistence | ||
autoload :Dependency, 'license_finder/persistence/yaml/dependency' | ||
autoload :Configuration, 'license_finder/persistence/yaml/configuration' | ||
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,34 @@ | ||
module LicenseFinder | ||
module Persistence | ||
class Configuration | ||
attr_reader :whitelist, :ignore_groups, :dependencies_dir | ||
|
||
def initialize(config={}) | ||
if File.exists?(config_file_path) | ||
yaml = File.read(config_file_path) | ||
config = YAML.load(yaml).merge config | ||
end | ||
|
||
@whitelist = config['whitelist'] || [] | ||
@ignore_groups = (config["ignore_groups"] || []).map(&:to_sym) | ||
@dependencies_dir = config['dependencies_file_dir'] || '.' | ||
end | ||
|
||
def config_file_path | ||
File.join('.', 'config', 'license_finder.yml') | ||
end | ||
|
||
def dependencies_yaml | ||
File.join(dependencies_dir, "dependencies.yml") | ||
end | ||
|
||
def dependencies_text | ||
File.join(dependencies_dir, "dependencies.txt") | ||
end | ||
|
||
def dependencies_html | ||
File.join(dependencies_dir, "dependencies.html") | ||
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
5 changes: 5 additions & 0 deletions
5
spec/lib/license_finder/persistence/yaml/configuration_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,5 @@ | ||
require "spec_helper" | ||
|
||
describe LicenseFinder::Persistence::Configuration do | ||
it_behaves_like "a persistable configuration" | ||
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,22 @@ | ||
shared_examples_for "a persistable configuration" do | ||
let(:klass) { described_class } | ||
|
||
let(:attributes) do | ||
{ | ||
"whitelist" => ["FooLicense", "BarLicense"], | ||
"ignore_groups" => [:test, :development] | ||
} | ||
end | ||
|
||
describe '.new' do | ||
subject { klass.new(attributes) } | ||
|
||
context "with known attributes" do | ||
it "should set the all of the attributes on the instance" do | ||
attributes.each do |key, value| | ||
subject.send("#{key}").should == 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