Class: LicenseFinder::NpmPackage
- Defined in:
- lib/license_finder/packages/npm_package.rb
Defined Under Namespace
Classes: Group, Identifier, PackageJson
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#json ⇒ Object
Returns the value of attribute json.
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
- #==(other) ⇒ Object
- #author_name(author) ⇒ Object
- #author_name_from_combined(author) ⇒ Object
- #author_names ⇒ Object
-
#initialize(npm_json, package_json = npm_json) ⇒ NpmPackage
constructor
A new instance of NpmPackage.
- #package_manager ⇒ Object
- #package_url ⇒ Object
- #to_s ⇒ Object
Methods inherited from Package
#<=>, #activations, #approved?, #approved_manually!, #approved_manually?, #decide_on_license, #eql?, #hash, #license_files, license_names_from_standard_spec, #licenses, #licenses_from_spec, #licensing, #log_activation, #missing?, #notice_files, #permitted!, #permitted?, #restricted!, #restricted?
Constructor Details
#initialize(npm_json, package_json = npm_json) ⇒ NpmPackage
Returns a new instance of NpmPackage.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/license_finder/packages/npm_package.rb', line 84 def initialize(npm_json, package_json = npm_json) @npm_json = npm_json @json = package_json @identifier = Identifier.from_hash(npm_json) @dependencies = deps_from_json super(@identifier.name, @identifier.version, description: package_json['description'], homepage: package_json['homepage'], authors: , spec_licenses: Package.license_names_from_standard_spec(package_json), install_path: npm_json['path'], children: @dependencies.map(&:name)) end |
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
5 6 7 |
# File 'lib/license_finder/packages/npm_package.rb', line 5 def dependencies @dependencies end |
#groups ⇒ Object
Returns the value of attribute groups.
5 6 7 |
# File 'lib/license_finder/packages/npm_package.rb', line 5 def groups @groups end |
#identifier ⇒ Object
Returns the value of attribute identifier.
5 6 7 |
# File 'lib/license_finder/packages/npm_package.rb', line 5 def identifier @identifier end |
#json ⇒ Object
Returns the value of attribute json.
5 6 7 |
# File 'lib/license_finder/packages/npm_package.rb', line 5 def json @json end |
Class Method Details
.packages_from_json(npm_json, package_path) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/license_finder/packages/npm_package.rb', line 8 def packages_from_json(npm_json, package_path) @packages = flattened_dependencies(npm_json) package_json = PackageJson.new(package_path) populate_groups(package_json) @packages.reject! do |_identifier, package| package.name.empty? && package.version.empty? && package.licenses.length == 1 && package.licenses.first.name == 'unknown' end @packages.values end |
Instance Method Details
#==(other) ⇒ Object
127 128 129 |
# File 'lib/license_finder/packages/npm_package.rb', line 127 def ==(other) other.is_a?(NpmPackage) && @identifier == other.identifier end |
#author_name(author) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/license_finder/packages/npm_package.rb', line 114 def () if .instance_of?(String) () else ['name'] end end |
#author_name_from_combined(author) ⇒ Object
122 123 124 125 |
# File 'lib/license_finder/packages/npm_package.rb', line 122 def () matches = .match(/^(.*?)\s*(<.*?>)?\s*(\(.*?\))?\s*$/) matches[1] end |
#author_names ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/license_finder/packages/npm_package.rb', line 99 def names = [] if @json['author'].is_a?(Array) # "author":["foo","bar"] isn't valid according to the NPM package.json schema, but can be found in the wild. names += @json['author'].map { |a| (a) } else names << (@json['author']) unless @json['author'].nil? end names += @json['contributors'].map { |c| (c) } if @json['contributors'].is_a?(Array) names.compact.join(', ') rescue TypeError puts "Warning: Invalid author and/or contributors metadata found in package.json for #{@identifier}" nil end |
#package_manager ⇒ Object
135 136 137 |
# File 'lib/license_finder/packages/npm_package.rb', line 135 def package_manager 'Npm' end |
#package_url ⇒ Object
139 140 141 |
# File 'lib/license_finder/packages/npm_package.rb', line 139 def package_url "https://www.npmjs.com/package/#{CGI.escape(name)}/v/#{CGI.escape(version)}" end |
#to_s ⇒ Object
131 132 133 |
# File 'lib/license_finder/packages/npm_package.rb', line 131 def to_s @identifier.to_s end |