Permalink
Browse files

Merge pull request #8 from utahstreetlabs/master

Allow dependencies file directory to be configured
  • Loading branch information...
2 parents eaf03f9 + a7d1860 commit cd074bf10184d33cfda5d95d7ea9fc4793af0879 @pivotalcommon pivotalcommon committed Jul 16, 2012
Showing with 29 additions and 6 deletions.
  1. +3 −2 files/license_finder.yml
  2. +17 −4 lib/license_finder/finder.rb
  3. +9 −0 spec/finder_spec.rb
View
5 files/license_finder.yml
@@ -1,7 +1,8 @@
----
-whitelist:
+---
+whitelist:
#- MIT
#- Apache 2.0
ignore_groups:
#- test
#- development
+dependencies_file_dir: './'
View
21 lib/license_finder/finder.rb
@@ -12,6 +12,19 @@ def initialize
@whitelist = config['whitelist'] || []
@ignore_groups = (config['ignore_groups'] || []).map{|g| g.to_sym}
+ @dependencies_dir = config['dependencies_file_dir']
+ end
+
+ def dependencies_dir
+ @dependencies_dir || './'
+ end
+
+ def dependencies_yaml
+ File.join(dependencies_dir, 'dependencies.yml')
+ end
+
+ def dependencies_text
+ File.join(dependencies_dir, 'dependencies.txt')
end
def from_bundler
@@ -22,10 +35,10 @@ def from_bundler
def write_files
new_list = generate_list
- File.open('./dependencies.yml', 'w+') do |f|
+ File.open(dependencies_yaml, 'w+') do |f|
f.puts new_list.to_yaml
end
- File.open('./dependencies.txt', 'w+') do |f|
+ File.open(dependencies_text, 'w+') do |f|
f.puts new_list.to_s
end
@@ -40,8 +53,8 @@ def action_items
def generate_list
bundler_list = DependencyList.from_bundler(whitelist, ignore_groups)
- if (File.exists?('./dependencies.yml'))
- yml = File.open('./dependencies.yml').readlines.join
+ if (File.exists?(dependencies_yaml))
+ yml = File.open(dependencies_yaml).readlines.join
existing_list = DependencyList.from_yaml(yml)
existing_list.merge(bundler_list)
else
View
9 spec/finder_spec.rb
@@ -56,6 +56,15 @@
LicenseFinder::Finder.new.ignore_groups.should == [:test, :development]
end
+ it 'should allow the dependencies file directory to be configured' do
+ stub(File).exists?('./config/license_finder.yml') {true}
+ stub(File).open('./config/license_finder.yml').stub!.readlines.stub!.join {"--- \nwhitelist: \n- MIT\n- Apache\nignore_groups: \n- test\n- development\ndependencies_file_dir: './elsewhere'\n"}
+ finder = LicenseFinder::Finder.new
+ finder.dependencies_dir.should == './elsewhere'
+ finder.dependencies_yaml.should == './elsewhere/dependencies.yml'
+ finder.dependencies_text.should == './elsewhere/dependencies.txt'
+ end
+
it "should load an empty ignore_groups list from license_finder.yml when there are no ignore groups" do
stub(File).exists?('./config/license_finder.yml') {true}
stub(File).open('./config/license_finder.yml').stub!.readlines.stub!.join {"--- \nwhitelist: \n- MIT\n- Apache\nignore_groups:"}

0 comments on commit cd074bf

Please sign in to comment.