Class: LicenseScout::Dependency
- Inherits:
-
Object
- Object
- LicenseScout::Dependency
- Defined in:
- lib/license_scout/dependency.rb
Instance Attribute Summary collapse
-
#license ⇒ Object
readonly
Returns the value of attribute license.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Be able to sort dependencies by type, then name, then version.
-
#add_license(license_id, source, contents_url = nil) ⇒ void
Capture a license that was specified in metadata.
-
#eql?(other) ⇒ Boolean
Whether or not this object is equal to another one.
- #exception_reason ⇒ Object
- #exceptions ⇒ Object
-
#has_exception? ⇒ Boolean
Determine if this dependency has an exception.
-
#hash ⇒ Integer
A hashcode that can be used to idenitfy this object.
-
#initialize(name, version, path, type) ⇒ Dependency
constructor
A new instance of Dependency.
-
#uid ⇒ String
The UID for this dependency.
-
#uid_regexp ⇒ Regexp
The regular expression that can be used to identify this dependency.
Constructor Details
#initialize(name, version, path, type) ⇒ Dependency
Returns a new instance of Dependency.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/license_scout/dependency.rb', line 31 def initialize(name, version, path, type) @name = name @version = version @path = path @type = type if path.nil? @license = LicenseScout::License.new elsif path =~ /^http/ || File.directory?(path) @license = LicenseScout::License.new(path) else raise LicenseScout::Exceptions::MissingSourceDirectory.new("Could not find the source for '#{name}' in the following directories:\n\t * #{path}") end fallbacks = LicenseScout::Config.fallbacks.send(type.to_sym).select { |f| f["name"] =~ uid_regexp } fallbacks.each do |fallback| license.add_license(fallback["license_id"], "license_scout fallback", fallback["license_file"], force: true) end end |
Instance Attribute Details
#license ⇒ Object (readonly)
Returns the value of attribute license.
29 30 31 |
# File 'lib/license_scout/dependency.rb', line 29 def license @license end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/license_scout/dependency.rb', line 21 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
25 26 27 |
# File 'lib/license_scout/dependency.rb', line 25 def path @path end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
27 28 29 |
# File 'lib/license_scout/dependency.rb', line 27 def type @type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
23 24 25 |
# File 'lib/license_scout/dependency.rb', line 23 def version @version end |
Instance Method Details
#<=>(other) ⇒ Object
Be able to sort dependencies by type, then name, then version
91 92 93 |
# File 'lib/license_scout/dependency.rb', line 91 def <=>(other) "#{type}#{name}#{version}" <=> "#{other.type}#{other.name}#{other.version}" end |
#add_license(license_id, source, contents_url = nil) ⇒ void
This method returns an undefined value.
Capture a license that was specified in metadata
72 73 74 75 |
# File 'lib/license_scout/dependency.rb', line 72 def add_license(license_id, source, contents_url = nil) LicenseScout::Log.debug("[#{type}] Adding #{license_id} license for #{name} from #{source}") license.add_license(license_id, source, contents_url, {}) end |
#eql?(other) ⇒ Boolean
Returns Whether or not this object is equal to another one. Used for Set uniqueness.
96 97 98 |
# File 'lib/license_scout/dependency.rb', line 96 def eql?(other) other.is_a?(self.class) && other.hash == hash end |
#exception_reason ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/license_scout/dependency.rb', line 82 def exception_reason if has_exception? exceptions.first.dig("reason") else nil end end |
#exceptions ⇒ Object
61 62 63 |
# File 'lib/license_scout/dependency.rb', line 61 def exceptions @exceptions ||= LicenseScout::Config.exceptions.send(type.to_sym).select { |e| e["name"] =~ uid_regexp } end |
#has_exception? ⇒ Boolean
Determine if this dependency has an exception. Will match an exception for both the name and the name+version
78 79 80 |
# File 'lib/license_scout/dependency.rb', line 78 def has_exception? exceptions.any? end |
#hash ⇒ Integer
Returns A hashcode that can be used to idenitfy this object. Used for Set uniqueness.
101 102 103 |
# File 'lib/license_scout/dependency.rb', line 101 def hash [type, name, version].hash end |
#uid ⇒ String
Returns The UID for this dependency. Example: bundler (1.16.1).
52 53 54 |
# File 'lib/license_scout/dependency.rb', line 52 def uid "#{name} (#{version})" end |
#uid_regexp ⇒ Regexp
Returns The regular expression that can be used to identify this dependency.
57 58 59 |
# File 'lib/license_scout/dependency.rb', line 57 def uid_regexp Regexp.new("#{Regexp.escape(name)}(\s+\\(#{Regexp.escape(version)}\\))?") end |