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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab35a217757c184a6a0b91d6536c8ab7a8b19c44
4
- data.tar.gz: 9cdabe6b6e388c2ef893f8e691aa1aa5aa7e78b2
3
+ metadata.gz: 78870e247e0c6151853578986d20c1c751367d5d
4
+ data.tar.gz: 44bb59c524289c3797c408ddd727fca8e808893d
5
5
  SHA512:
6
- metadata.gz: 41e4cff0f46f818a9cacfc83b7e0bb495b59152e29e9a95a12a9296e0a87d0b051ac009c329ef435804051076281724ece0c18612ebe7e38a53ed230830f7466
7
- data.tar.gz: d69564bffdc75c6af44a36795d7cee2c5dddf8b91cb65ce92e1eb3345ecc31500c31a2a2a47b828c0476181356a39c76c00a0e6f94775a3b1e27224a7d55d9ce
6
+ metadata.gz: beda36d600d5771bf870f627547800aa561641f2755c2f9a6662b7e7b14dfdb743075ecfd45145bfe6050c8f3aedcf9c3b65f70b10d5f0edab22b1c4a10bf7cb
7
+ data.tar.gz: d66f22ef8340ccfb6c9ca11fdbd1c5e403ba26c5f8a21776cd5f88dfa2fc8bf71322b5fc0895412091cd78ccbf39fba099953a5bec51c62e129c99c95c308cf7
@@ -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'
@@ -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
- return @rules if defined? @rules
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
@@ -1,5 +1,3 @@
1
- require 'yaml'
2
-
3
1
  module Licensee
4
2
  class LicenseMeta < Struct.new(
5
3
  :title, :spdx_id, :source, :description, :how, :conditions, :permissions,
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Licensee
2
- VERSION = '9.1.0'.freeze
2
+ VERSION = '9.2.0'.freeze
3
3
  end
@@ -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(6)
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.1.0
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-03 00:00:00.000000000 Z
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