Class: Licensed::Source::NPM
- Inherits:
-
Object
- Object
- Licensed::Source::NPM
- Defined in:
- lib/licensed/source/npm.rb
Instance Method Summary collapse
- #command ⇒ Object
- #dependencies ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(config) ⇒ NPM
constructor
A new instance of NPM.
- #recursive_dependencies(dependencies, result = {}) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(config) ⇒ NPM
Returns a new instance of NPM.
6 7 8 |
# File 'lib/licensed/source/npm.rb', line 6 def initialize(config) @config = config end |
Instance Method Details
#command ⇒ Object
34 35 36 |
# File 'lib/licensed/source/npm.rb', line 34 def command `npm list --json --production --long` end |
#dependencies ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/licensed/source/npm.rb', line 18 def dependencies return @dependencies if defined?(@dependencies) packages = recursive_dependencies(JSON.parse(command)["dependencies"]) @dependencies = packages.map do |name, package| Dependency.new(package["realPath"], { "type" => type, "name" => package["name"], "version" => package["version"], "summary" => package["description"], "homepage" => package["homepage"] }) end end |
#enabled? ⇒ Boolean
14 15 16 |
# File 'lib/licensed/source/npm.rb', line 14 def enabled? @config.enabled?(type) && File.exist?(@config.pwd.join("package.json")) end |
#recursive_dependencies(dependencies, result = {}) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/licensed/source/npm.rb', line 38 def recursive_dependencies(dependencies, result = {}) dependencies.each do |name, dependency| (result[name] ||= {}).update(dependency) recursive_dependencies(dependency["dependencies"] || {}, result) end result end |
#type ⇒ Object
10 11 12 |
# File 'lib/licensed/source/npm.rb', line 10 def type "npm" end |