Class: LicenseFinder::NpmPackage::PackageJson
- Inherits:
-
Object
- Object
- LicenseFinder::NpmPackage::PackageJson
- Defined in:
- lib/license_finder/packages/npm_package.rb
Constant Summary collapse
- DEPENDENCY_GROUPS =
%w[dependencies devDependencies].freeze
Instance Attribute Summary collapse
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
Instance Method Summary collapse
- #groups_for(identifier) ⇒ Object
-
#initialize(path) ⇒ PackageJson
constructor
A new instance of PackageJson.
Constructor Details
#initialize(path) ⇒ PackageJson
Returns a new instance of PackageJson.
161 162 163 164 |
# File 'lib/license_finder/packages/npm_package.rb', line 161 def initialize(path) json = JSON.parse(File.read(path), max_nesting: false) @groups = DEPENDENCY_GROUPS.map { |name| Group.new(name, json.fetch(name, {})) } end |
Instance Attribute Details
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
158 159 160 |
# File 'lib/license_finder/packages/npm_package.rb', line 158 def groups @groups end |
Instance Method Details
#groups_for(identifier) ⇒ Object
166 167 168 |
# File 'lib/license_finder/packages/npm_package.rb', line 166 def groups_for(identifier) @groups.select { |g| g.include? identifier }.map(&:name) end |