licensee 9.1.0 → 9.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/licensee.rb +2 -0
- data/lib/licensee/license.rb +1 -12
- data/lib/licensee/license_meta.rb +0 -2
- data/lib/licensee/license_rules.rb +34 -0
- data/lib/licensee/version.rb +1 -1
- data/spec/licensee/license_rules_spec.rb +45 -0
- data/spec/licensee/license_spec.rb +2 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78870e247e0c6151853578986d20c1c751367d5d
|
4
|
+
data.tar.gz: 44bb59c524289c3797c408ddd727fca8e808893d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: beda36d600d5771bf870f627547800aa561641f2755c2f9a6662b7e7b14dfdb743075ecfd45145bfe6050c8f3aedcf9c3b65f70b10d5f0edab22b1c4a10bf7cb
|
7
|
+
data.tar.gz: d66f22ef8340ccfb6c9ca11fdbd1c5e403ba26c5f8a21776cd5f88dfa2fc8bf71322b5fc0895412091cd78ccbf39fba099953a5bec51c62e129c99c95c308cf7
|
data/lib/licensee.rb
CHANGED
@@ -2,11 +2,13 @@ require_relative 'licensee/version'
|
|
2
2
|
require 'forwardable'
|
3
3
|
require 'pathname'
|
4
4
|
require 'rugged'
|
5
|
+
require 'yaml'
|
5
6
|
|
6
7
|
module Licensee
|
7
8
|
autoload :ContentHelper, 'licensee/content_helper'
|
8
9
|
autoload :License, 'licensee/license'
|
9
10
|
autoload :LicenseMeta, 'licensee/license_meta'
|
11
|
+
autoload :LicenseRules, 'licensee/license_rules'
|
10
12
|
autoload :Rule, 'licensee/rule'
|
11
13
|
autoload :Matchers, 'licensee/matchers'
|
12
14
|
autoload :Projects, 'licensee/projects'
|
data/lib/licensee/license.rb
CHANGED
@@ -134,19 +134,8 @@ module Licensee
|
|
134
134
|
PSEUDO_LICENSES.include?(key)
|
135
135
|
end
|
136
136
|
|
137
|
-
# Returns a hash in the form of rule_group => rules describing
|
138
|
-
# what you legally can and can't do with the given license
|
139
137
|
def rules
|
140
|
-
|
141
|
-
@rules = {}
|
142
|
-
|
143
|
-
Rule.groups.each do |group|
|
144
|
-
@rules[group] = meta[group].map do |tag|
|
145
|
-
Rule.find_by_tag_and_group(tag, group)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
@rules
|
138
|
+
@rules ||= LicenseRules.from_meta(meta)
|
150
139
|
end
|
151
140
|
|
152
141
|
def inspect
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Licensee
|
2
|
+
# Exposes #conditions, #permissions, and #limitation arrays of LicenseRules
|
3
|
+
class LicenseRules < Struct.new(:conditions, :permissions, :limitations)
|
4
|
+
class << self
|
5
|
+
def from_license(license)
|
6
|
+
from_meta(license.meta)
|
7
|
+
end
|
8
|
+
|
9
|
+
def from_meta(meta)
|
10
|
+
rules = {}
|
11
|
+
Rule.groups.each do |group|
|
12
|
+
rules[group] = meta[group].map do |tag|
|
13
|
+
Rule.find_by_tag_and_group(tag, group)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
from_hash(rules)
|
17
|
+
end
|
18
|
+
|
19
|
+
def from_hash(hash)
|
20
|
+
ordered_array = hash.values_at(*members.map(&:to_s))
|
21
|
+
new(*ordered_array)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def flatten
|
26
|
+
members.map { |m| public_send(m) }.flatten
|
27
|
+
end
|
28
|
+
|
29
|
+
def key?(key)
|
30
|
+
members.include?(key.to_sym)
|
31
|
+
end
|
32
|
+
alias has_key? key?
|
33
|
+
end
|
34
|
+
end
|
data/lib/licensee/version.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
RSpec.describe Licensee::LicenseRules do
|
2
|
+
let(:mit) { Licensee::License.find('mit') }
|
3
|
+
subject { mit.rules }
|
4
|
+
|
5
|
+
Licensee::Rule.groups.each do |group|
|
6
|
+
context "the #{group} rule group" do
|
7
|
+
it 'responds as a hash key string' do
|
8
|
+
expect(subject[group]).to be_a(Array)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'responds as a hash key symbol' do
|
12
|
+
expect(subject[group.to_sym]).to be_a(Array)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'responds as a method' do
|
16
|
+
expect(subject.public_send(group.to_sym)).to be_a(Array)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'created from a license' do
|
22
|
+
subject { described_class.from_license(mit) }
|
23
|
+
|
24
|
+
it 'exposes the rules' do
|
25
|
+
expect(subject.permissions.first.label).to eql('Commercial use')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'created from a meta' do
|
30
|
+
subject { described_class.from_meta(mit.meta) }
|
31
|
+
|
32
|
+
it 'exposes the rules' do
|
33
|
+
expect(subject.permissions.first.label).to eql('Commercial use')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'created from a hash' do
|
38
|
+
let(:hash) { { 'permissions' => Licensee::Rule.all } }
|
39
|
+
subject { described_class.from_hash(hash) }
|
40
|
+
|
41
|
+
it 'exposes the rules' do
|
42
|
+
expect(subject.permissions.first.label).to eql('Commercial use')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -250,9 +250,10 @@ RSpec.describe Licensee::License do
|
|
250
250
|
end
|
251
251
|
|
252
252
|
it 'returns the rules' do
|
253
|
+
expect(mit.rules).to be_a(Licensee::LicenseRules)
|
253
254
|
expect(mit.rules).to have_key('permissions')
|
254
255
|
expect(mit.rules['permissions'].first).to be_a(Licensee::Rule)
|
255
|
-
expect(mit.rules.flatten.count).to eql(
|
256
|
+
expect(mit.rules.flatten.count).to eql(7)
|
256
257
|
end
|
257
258
|
|
258
259
|
it 'returns rules by tag and group' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: licensee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.
|
4
|
+
version: 9.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rugged
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/licensee/content_helper.rb
|
110
110
|
- lib/licensee/license.rb
|
111
111
|
- lib/licensee/license_meta.rb
|
112
|
+
- lib/licensee/license_rules.rb
|
112
113
|
- lib/licensee/matchers.rb
|
113
114
|
- lib/licensee/matchers/cabal.rb
|
114
115
|
- lib/licensee/matchers/copyright.rb
|
@@ -158,6 +159,7 @@ files:
|
|
158
159
|
- spec/integration_spec.rb
|
159
160
|
- spec/licensee/content_helper_spec.rb
|
160
161
|
- spec/licensee/license_meta_spec.rb
|
162
|
+
- spec/licensee/license_rules_spec.rb
|
161
163
|
- spec/licensee/license_spec.rb
|
162
164
|
- spec/licensee/matchers/cabal_matcher_spec.rb
|
163
165
|
- spec/licensee/matchers/copyright_matcher_spec.rb
|