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.
209 210 211 212 |
# File 'lib/license_finder/packages/npm_package.rb', line 209 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.
205 206 207 |
# File 'lib/license_finder/packages/npm_package.rb', line 205 def groups @groups end |
Instance Method Details
#groups_for(identifier) ⇒ Object
214 215 216 |
# File 'lib/license_finder/packages/npm_package.rb', line 214 def groups_for(identifier) @groups.select { |g| g.include? identifier }.map(&:name) end |