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.
151 152 153 154 |
# File 'lib/license_finder/packages/npm_package.rb', line 151 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.
148 149 150 |
# File 'lib/license_finder/packages/npm_package.rb', line 148 def groups @groups end |
Instance Method Details
#groups_for(identifier) ⇒ Object
156 157 158 |
# File 'lib/license_finder/packages/npm_package.rb', line 156 def groups_for(identifier) @groups.select { |g| g.include? identifier }.map(&:name) end |