Class: LicenseFinder::Package
- Inherits:
-
Object
- Object
- LicenseFinder::Package
- Defined in:
- lib/license_finder/package.rb
Overview
Super-class that adapts data from different package management systems (gems, npm, pip, etc.) to a common interface.
Guidance on adding a new system
-
subclass Package, and initialize based on the data you receive from the package manager
-
if the package specs will report license names, pass :spec_licenses in the constructor options
-
if the package’s files can be searched for licenses pass :install_path in the constructor options
-
otherwise, override #licenses_from_spec or #license_files
Direct Known Subclasses
BowerPackage, BundlerPackage, CocoaPodsPackage, GradlePackage, ManualPackage, MavenPackage, NpmPackage, PipPackage, RebarPackage
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#homepage ⇒ Object
readonly
Returns the value of attribute homepage.
-
#install_path ⇒ Object
readonly
checked in tests, otherwise private.
-
#license_names_from_spec ⇒ Object
readonly
LICENSING.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#manual_approval ⇒ Object
readonly
Returns the value of attribute manual_approval.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parents ⇒ Object
readonly
Returns the value of attribute parents.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #activations ⇒ Object
- #approved? ⇒ Boolean
-
#approved_manually!(approval) ⇒ Object
APPROVAL.
- #approved_manually? ⇒ Boolean
- #decide_on_license(license) ⇒ Object
-
#initialize(name, version = nil, options = {}) ⇒ Package
constructor
A new instance of Package.
- #license_files ⇒ Object
- #licenses ⇒ Object
- #licenses_from_spec ⇒ Object
- #licensing ⇒ Object
- #missing? ⇒ Boolean
- #whitelisted! ⇒ Object
- #whitelisted? ⇒ Boolean
Constructor Details
#initialize(name, version = nil, options = {}) ⇒ Package
Returns a new instance of Package.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/license_finder/package.rb', line 32 def initialize(name, version = nil, ={}) @logger = [:logger] || Core.default_logger @name = name @version = version @summary = [:summary] || "" @description = [:description] || "" @homepage = [:homepage] || "" @children = [:children] || [] @parents = Set.new # will be figured out later by package manager @groups = [:groups] || [] ## APPROVAL @whitelisted = false @manual_approval = nil ## LICENSING @license_names_from_spec = [:spec_licenses] || [] @install_path = [:install_path] @missing = [:missing] || false @decided_licenses = Set.new end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
55 56 57 |
# File 'lib/license_finder/package.rb', line 55 def children @children end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
55 56 57 |
# File 'lib/license_finder/package.rb', line 55 def description @description end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
55 56 57 |
# File 'lib/license_finder/package.rb', line 55 def groups @groups end |
#homepage ⇒ Object (readonly)
Returns the value of attribute homepage.
55 56 57 |
# File 'lib/license_finder/package.rb', line 55 def homepage @homepage end |
#install_path ⇒ Object (readonly)
checked in tests, otherwise private
86 87 88 |
# File 'lib/license_finder/package.rb', line 86 def install_path @install_path end |
#license_names_from_spec ⇒ Object (readonly)
LICENSING
85 86 87 |
# File 'lib/license_finder/package.rb', line 85 def license_names_from_spec @license_names_from_spec end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
18 19 20 |
# File 'lib/license_finder/package.rb', line 18 def logger @logger end |
#manual_approval ⇒ Object (readonly)
Returns the value of attribute manual_approval.
81 82 83 |
# File 'lib/license_finder/package.rb', line 81 def manual_approval @manual_approval end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
55 56 57 |
# File 'lib/license_finder/package.rb', line 55 def name @name end |
#parents ⇒ Object (readonly)
Returns the value of attribute parents.
55 56 57 |
# File 'lib/license_finder/package.rb', line 55 def parents @parents end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
55 56 57 |
# File 'lib/license_finder/package.rb', line 55 def summary @summary end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
55 56 57 |
# File 'lib/license_finder/package.rb', line 55 def version @version end |
Class Method Details
.license_names_from_standard_spec(spec) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/license_finder/package.rb', line 20 def self.license_names_from_standard_spec(spec) licenses = spec["licenses"] || [spec["license"]].compact licenses = [licenses] unless licenses.is_a?(Array) licenses.map do |license| if license.is_a? Hash license["type"] else license end end end |
Instance Method Details
#activations ⇒ Object
92 93 94 95 96 |
# File 'lib/license_finder/package.rb', line 92 def activations licensing.activations.tap do |activations| activations.each { |activation| logger.activation(activation) } end end |
#approved? ⇒ Boolean
69 70 71 |
# File 'lib/license_finder/package.rb', line 69 def approved? approved_manually? || whitelisted? end |
#approved_manually!(approval) ⇒ Object
APPROVAL
61 62 63 |
# File 'lib/license_finder/package.rb', line 61 def approved_manually!(approval) @manual_approval = approval end |
#approved_manually? ⇒ Boolean
73 74 75 |
# File 'lib/license_finder/package.rb', line 73 def approved_manually? !@manual_approval.nil? end |
#decide_on_license(license) ⇒ Object
102 103 104 |
# File 'lib/license_finder/package.rb', line 102 def decide_on_license(license) @decided_licenses << license end |
#license_files ⇒ Object
112 113 114 |
# File 'lib/license_finder/package.rb', line 112 def license_files LicenseFiles.find(install_path) end |
#licenses ⇒ Object
88 89 90 |
# File 'lib/license_finder/package.rb', line 88 def licenses @licenses ||= activations.map(&:license).to_set end |
#licenses_from_spec ⇒ Object
106 107 108 109 110 |
# File 'lib/license_finder/package.rb', line 106 def licenses_from_spec license_names_from_spec .map { |name| License.find_by_name(name) } .to_set end |
#licensing ⇒ Object
98 99 100 |
# File 'lib/license_finder/package.rb', line 98 def licensing Licensing.new(self, @decided_licenses, licenses_from_spec, license_files) end |
#missing? ⇒ Boolean
116 117 118 |
# File 'lib/license_finder/package.rb', line 116 def missing? @missing end |
#whitelisted! ⇒ Object
65 66 67 |
# File 'lib/license_finder/package.rb', line 65 def whitelisted! @whitelisted = true end |
#whitelisted? ⇒ Boolean
77 78 79 |
# File 'lib/license_finder/package.rb', line 77 def whitelisted? @whitelisted end |