gem-license 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 86ddc134de3304378496bf70a06b5c0b1d356c497f8efc2d05302374e558e855
4
+ data.tar.gz: 14ad79c931803710aac2010d337eb22d865e158804c48bdd93ba8fdd2919c7ed
5
+ SHA512:
6
+ metadata.gz: 8811aa0cd2824b2c0b865d84ecfa6e1dbec978fb413e905f121dad77373ee7e022a84a5cd231628f8e8303b5290fd7d7800755fbac057a72a23dd5415e44f157
7
+ data.tar.gz: d3b0f87a9fb1fb2a1055749ef942d682a75df96cdc39f3bda3f2bf2f1f4cd59d7f9c2c40dc1426605c4497a123312606c587f651eee19c756497123a383ee384
data/.gitignore ADDED
@@ -0,0 +1,53 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ Style/ClassAndModuleChildren:
2
+ Exclude:
3
+ - "lib/rubygems/commands/license_command.rb"
4
+
5
+ Metrics/LineLength:
6
+ Max: 110
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) <year> <copyright holders>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # gem-license
2
+
3
+ A gem plugin for fetching licenses
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ gem install gem-license
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```sh
14
+ gem license mit
15
+
16
+ # output to stdout
17
+ gem license gpl-3.0
18
+
19
+ # create a LICENSE.md
20
+ gem license apl-1.0
21
+ ```
22
+
23
+ Licenses names are all based on SPDX identifiers and are not case sensitive.
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/swarley/gem-license.
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'gem-license'
5
+ spec.version = '0.1.0'
6
+ spec.authors = ['Matt Carey']
7
+ spec.email = ['matthew.b.carey@gmail.com']
8
+
9
+ spec.summary = 'Gem plugin to download licenses'
10
+ spec.description = 'Gem plugin to download a LICENSE file based on its shortname'
11
+ spec.license = 'MIT'
12
+
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.bindir = 'exe'
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_development_dependency 'bundler', '~> 2.0.1'
19
+ spec.add_development_dependency 'rubocop', '~> 0.69'
20
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open-uri'
4
+ require 'json'
5
+
6
+ # license gem plugin
7
+ class Gem::Commands::LicenseCommand < Gem::Command
8
+ def initialize
9
+ super('license', 'Download a license by SPDX id')
10
+
11
+ add_option('-m', '--markdown', 'Download as LICENSE.md') do |_, options|
12
+ options[:markdown] = true
13
+ end
14
+
15
+ add_option('-s', '--stdout', 'Write to STDOUT instead of LICENSE') do |_, options|
16
+ options[:stdout] = true
17
+ end
18
+ end
19
+
20
+ def fetch_license_list
21
+ list_uri = URI('https://spdx.org/licenses/licenses.json')
22
+ JSON.parse(list_uri.read)
23
+ rescue OpenURI::HTTPError => e
24
+ raise Gem::CommandLineError, "Unable to get license list. [#{e.message}]"
25
+ end
26
+
27
+ def fetch_license_text(url)
28
+ license_uri = URI(url)
29
+ license_obj = JSON.parse(license_uri.read)
30
+ license_obj['licenseText']
31
+ rescue OpenURI::HTTPError => e
32
+ raise Gem::CommandLineError, "Unable to get license text. [#{e.message}]"
33
+ end
34
+
35
+ def match_license_id(license_id, id_list)
36
+ license_id_rxp = Regexp.new(Regexp.escape(license_id), Regexp::IGNORECASE)
37
+ matched_ids = id_list.select { |id| id =~ license_id_rxp }
38
+
39
+ perfect_match = matched_ids.find { |id| id =~ /\A#{license_id_rxp}\Z/i }
40
+
41
+ unless perfect_match
42
+ say 'Unable to find an exact match. Suggestions below'
43
+ matched_ids.each { |id| say "\t#{id}" }
44
+ exit
45
+ end
46
+
47
+ perfect_match
48
+ end
49
+
50
+ def write_license(license_obj)
51
+ text = fetch_license_text(license_obj['detailsUrl'])
52
+ if options[:stdout]
53
+ say text
54
+ else
55
+ fname = 'LICENSE'
56
+ fname += '.md' if options[:markdown]
57
+ File.open(fname, 'w+') do |f|
58
+ f.write text
59
+ end
60
+ end
61
+ end
62
+
63
+ def download(shortname)
64
+ license_list = fetch_license_list['licenses']
65
+ id_list = license_list.collect { |l_obj| l_obj['licenseId'] }
66
+
67
+ id = match_license_id(shortname, id_list)
68
+ license_obj = license_list.find { |l_obj| l_obj['licenseId'] == id }
69
+
70
+ write_license license_obj
71
+ end
72
+
73
+ def execute
74
+ id = options[:args].first
75
+ download(id)
76
+ end
77
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems/command_manager'
4
+
5
+ Gem::CommandManager.instance.register_command(:license)
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-license
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Carey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.69'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.69'
41
+ description: Gem plugin to download a LICENSE file based on its shortname
42
+ email:
43
+ - matthew.b.carey@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rubocop.yml"
50
+ - LICENSE
51
+ - README.md
52
+ - gem-license.gemspec
53
+ - lib/rubygems/commands/license_command.rb
54
+ - lib/rubygems_plugin.rb
55
+ homepage:
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.0.1
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Gem plugin to download licenses
78
+ test_files: []