deriving_license 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rake", ">= 0.8.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deriving_license (0.1.0)
5
+ gemnasium-parser
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ gemnasium-parser (0.1.9)
11
+ rake (10.0.4)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ deriving_license!
18
+ rake (>= 0.8.7)
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ deriving_license
2
+ ================
3
+
4
+ Finds the license agreements for all gems in your Gemfile
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'deriving_license'
4
+ puts DerivingLicense.run(ARGV[0])
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'deriving_license'
3
+ s.version = '0.1.0'
4
+ s.summary = "Deriving Licence finds the license agreements for all gems in your Gemfile"
5
+ s.description = "Deriving Licence finds the license agreements for all gems in your Gemfile if included in your project, or in a Gemfile passed to the included binary"
6
+ s.authors = ["Tom Allen"]
7
+ s.email = 'tom@jugglethis.net'
8
+ s.homepage = 'http://www.github.com/Schwolop/deriving_license'
9
+ s.executables << 'deriving_license'
10
+
11
+ s.require_paths = ["lib"]
12
+ s.files = `git ls-files`.split($\)
13
+ s.test_files = s.files.grep(/^test\//)
14
+
15
+ s.add_dependency "gemnasium-parser"
16
+ end
@@ -0,0 +1,31 @@
1
+ require "gemnasium/parser"
2
+
3
+ class DerivingLicense
4
+ def self.run(path=nil)
5
+ unless path
6
+ raise ArgumentError.new("Path to Gemfile or Gemspec required")
7
+ end
8
+
9
+ unless /(gemfile|gemspec)+/.match(path.downcase)
10
+ raise ArgumentError.new("Argument must be a path to Gemfile or Gemspec")
11
+ end
12
+
13
+ begin
14
+ content = File.open(path, "r").read
15
+ rescue
16
+ raise "Invalid path to gemfile or gemspec."
17
+ end
18
+
19
+ gemfile = Gemnasium::Parser::Gemfile.new(content)
20
+
21
+ licenses = Hash.new(0)
22
+ gemfile.dependencies.each do |d|
23
+ # See if it's installed locally, and if not add -r to call
24
+ remote = /#{d.name}/.match( `gem list #{d.name}` ) ? "" : "-r "
25
+
26
+ spec = eval `gem specification #{remote}#{d.name} --ruby`
27
+ spec.licenses.each{ |l| licenses[l]+=1 }
28
+ end
29
+ licenses
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ require 'test/unit'
2
+ require 'deriving_license'
3
+
4
+ class DerivingLicenseTest < Test::Unit::TestCase
5
+ def test_run_throws_with_no_args
6
+ assert_raise ArgumentError do
7
+ DerivingLicense.run()
8
+ end
9
+ end
10
+
11
+ def test_run_throws_with_multiple_args
12
+ assert_raise ArgumentError do
13
+ DerivingLicense.run("Gemfile1", "Gemfile2")
14
+ end
15
+ end
16
+
17
+ def test_run_throws_if_path_is_invalid
18
+ assert_raise ArgumentError do
19
+ DerivingLicense.run("Ceci n'est pas un dossier.")
20
+ end
21
+ end
22
+
23
+ def test_run_throws_if_path_is_invalid_but_matches_gemfile_regex
24
+ assert_raise RuntimeError do
25
+ DerivingLicense.run("Ceci n'est pas un gemfile.")
26
+ end
27
+ end
28
+
29
+ def test_run_with_valid_arg
30
+ assert_nothing_raised do
31
+ DerivingLicense.run("Gemfile")
32
+ end
33
+ assert_equal( {"MIT"=>1}, DerivingLicense.run("Gemfile") )
34
+ end
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deriving_license
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tom Allen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gemnasium-parser
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Deriving Licence finds the license agreements for all gems in your Gemfile
31
+ if included in your project, or in a Gemfile passed to the included binary
32
+ email: tom@jugglethis.net
33
+ executables:
34
+ - deriving_license
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - README.md
41
+ - Rakefile
42
+ - bin/deriving_license
43
+ - deriving_license.gemspec
44
+ - lib/deriving_license.rb
45
+ - test/test_deriving_license.rb
46
+ homepage: http://www.github.com/Schwolop/deriving_license
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.24
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Deriving Licence finds the license agreements for all gems in your Gemfile
70
+ test_files:
71
+ - test/test_deriving_license.rb