Class: LicenseFinder::NpmPackage::PackageJson

Inherits:
Object
  • Object
show all
Defined in:
lib/license_finder/package_managers/npm_package.rb

Constant Summary collapse

DEPENDENCY_GROUPS =
%w(dependencies devDependencies)

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PackageJson

Returns a new instance of PackageJson.



144
145
146
147
# File 'lib/license_finder/package_managers/npm_package.rb', line 144

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 Method Details

#groups(identifier) ⇒ Object



149
150
151
# File 'lib/license_finder/package_managers/npm_package.rb', line 149

def groups(identifier)
  @groups.select { |g| g.include? identifier }.map(&:name)
end