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.



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

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