Class: LicenseFinder::NpmPackage::PackageJson

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

Constant Summary collapse

DEPENDENCY_GROUPS =
%w[dependencies devDependencies].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#groupsObject (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