Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow dependencies file directory to be configured

Allow projects to configure the location where dependencies.txt
and dependencies.yml are written using the dependencies_file_dir
config variable.
  • Loading branch information...
commit 8fbb501b7c2a51fb29fbe4f727341ed23c45ea6a 1 parent c2f2e9f
@travis travis authored
View
5 files/license_finder.yml
@@ -1,7 +1,8 @@
----
-whitelist:
+---
+whitelist:
#- MIT
#- Apache 2.0
ignore_groups:
#- test
#- development
+dependencies_file_dir: './'
View
23 lib/license_finder/finder.rb
@@ -7,9 +7,22 @@ def initialize
config = YAML.load(File.open('./config/license_finder.yml').readlines.join)
@whitelist = config['whitelist'] || []
@ignore_groups = config['ignore_groups'] ? config['ignore_groups'].map{|g| g.to_sym} : []
+ @dependencies_dir = config['dependencies_file_dir']
end
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
require 'bundler'
Bundler.load.specs.map { |spec| GemSpecDetails.new(spec) }.sort_by &:sort_order
@@ -18,10 +31,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
@@ -36,8 +49,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
@@ -45,4 +58,4 @@ def generate_list
end
end
end
-end
+end
View
11 spec/finder_spec.rb
@@ -41,4 +41,13 @@
stub(File).open('./config/license_finder.yml').stub!.readlines.stub!.join {"--- \nwhitelist: \n- MIT\n- Apache\nignore_groups: \n- test\n- development\n"}
LicenseFinder::Finder.new.ignore_groups.should == [:test, :development]
end
-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
+end
Please sign in to comment.
Something went wrong with that request. Please try again.