Class: LicenseScout::DependencyManager::Npm

Inherits:
Base
  • Object
show all
Defined in:
lib/license_scout/dependency_manager/npm.rb

Instance Attribute Summary

Attributes inherited from Base

#directory

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from LicenseScout::DependencyManager::Base

Instance Method Details

#dependenciesObject


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/license_scout/dependency_manager/npm.rb', line 44

def dependencies
  all_package_json_files.inject(Set.new) do |uniq_deps, package_json_file|
    pkg_info = File.open(package_json_file) do |f|
      FFI_Yajl::Parser.parse(f)
    end

    dep_name = pkg_info["name"]
    dep_version = pkg_info["version"]
    dep_path = File.dirname(package_json_file)

    dependency = new_dependency(dep_name, dep_version, dep_path)

    license_info = pkg_info["license"] || pkg_info["licenses"]

    case license_info
    when String
      dependency.add_license(license_info, "package.json")
    when Hash
      dependency.add_license(license_info["type"], "package.json", license_info["url"])
    when Array
      license_info.each do |license|
        case license
        when String
          dependency.add_license(license, "package.json")
        when Hash
          dependency.add_license(license["type"], "package.json", license["url"])
        end
      end
    end

    uniq_deps << dependency
  end.to_a
end

#detected?Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/license_scout/dependency_manager/npm.rb', line 40

def detected?
  File.exist?(root_node_modules_path)
end

#install_commandObject


36
37
38
# File 'lib/license_scout/dependency_manager/npm.rb', line 36

def install_command
  "npm install"
end

#nameObject


24
25
26
# File 'lib/license_scout/dependency_manager/npm.rb', line 24

def name
  "nodejs_npm"
end

#signatureObject


32
33
34
# File 'lib/license_scout/dependency_manager/npm.rb', line 32

def signature
  "node_modules directory"
end

#typeObject


28
29
30
# File 'lib/license_scout/dependency_manager/npm.rb', line 28

def type
  "nodejs"
end