Class: LicenseFinder::NpmPackage
- Inherits:
-
Package
- Object
- Package
- LicenseFinder::NpmPackage
show all
- Defined in:
- lib/license_finder/package_managers/npm_package.rb
Defined Under Namespace
Classes: Group, Identifier, PackageJson
Instance Attribute Summary collapse
Attributes inherited from Package
#authors, #children, #description, #homepage, #install_path, #license_names_from_spec, #logger, #manual_approval, #name, #parents, #summary, #version
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Package
#<=>, #activations, #approved?, #approved_manually!, #approved_manually?, #blacklisted!, #blacklisted?, #decide_on_license, #eql?, #hash, #license_files, license_names_from_standard_spec, #licenses, #licenses_from_spec, #licensing, #missing?, #whitelisted!, #whitelisted?
Constructor Details
#initialize(npm_json, root = self) ⇒ NpmPackage
Returns a new instance of NpmPackage.
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 14
def initialize(npm_json, root=self)
@identifier = Identifier.from_hash(npm_json)
@root = root
@dependencies = npm_json.fetch('dependencies', {}).values.map { |d| NpmPackage.new(d, root) }
super(@identifier.name,
@identifier.version,
description: npm_json['description'],
homepage: npm_json['homepage'],
spec_licenses: Package.license_names_from_standard_spec(npm_json),
install_path: npm_json['path'],
children: @dependencies.map(&:name))
end
|
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
3
4
5
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 3
def dependencies
@dependencies
end
|
#groups ⇒ Object
Returns the value of attribute groups.
3
4
5
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 3
def groups
@groups
end
|
#identifier ⇒ Object
Returns the value of attribute identifier.
3
4
5
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 3
def identifier
@identifier
end
|
Class Method Details
.packages_from_json(npm_json, package_path) ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 5
def self.packages_from_json(npm_json, package_path)
root_package = NpmPackage.new(npm_json).decircularize
package_json = PackageJson.new(package_path)
root_package.dependencies.each { |d| d.groups = package_json.groups(d.identifier) }
root_package.propagate_groups
flattened_deps = root_package.dependencies.map(&:flattened_dependencies).flatten
merge_dependencies flattened_deps
end
|
Instance Method Details
#==(other) ⇒ Object
52
53
54
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 52
def ==(other)
other.is_a?(NpmPackage) && @identifier == other.identifier
end
|
#decircularize ⇒ Object
34
35
36
37
38
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 34
def decircularize
noncircular = @root.find_noncircular(@identifier)
noncircular.dependencies |= @dependencies.map(&:decircularize)
noncircular
end
|
#find_noncircular(identifier) ⇒ Object
44
45
46
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 44
def find_noncircular(identifier)
flattened_dependencies.select{ |p| p.identifier == identifier }.find(&:noncircular?)
end
|
#flattened_dependencies ⇒ Object
40
41
42
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 40
def flattened_dependencies
[self] + @dependencies.map(&:flattened_dependencies).flatten(1)
end
|
#noncircular? ⇒ Boolean
48
49
50
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 48
def noncircular?
@licenses != ['[Circular]']
end
|
#package_manager ⇒ Object
60
61
62
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 60
def package_manager
'Npm'
end
|
#propagate_groups ⇒ Object
27
28
29
30
31
32
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 27
def propagate_groups
@dependencies.each do |child|
child.groups |= @groups
child.propagate_groups
end
end
|
#to_s ⇒ Object
56
57
58
|
# File 'lib/license_finder/package_managers/npm_package.rb', line 56
def to_s
@identifier.to_s
end
|