Class: NpmPackage
- Inherits:
-
Object
- Object
- NpmPackage
- Defined in:
- lib/resources/npm.rb
Overview
author: Christoph Hartmann author: Dominik Richter
Instance Method Summary collapse
- #info ⇒ Object
-
#initialize(package_name) ⇒ NpmPackage
constructor
A new instance of NpmPackage.
- #installed? ⇒ Boolean
- #to_s ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(package_name) ⇒ NpmPackage
Returns a new instance of NpmPackage.
14 15 16 17 |
# File 'lib/resources/npm.rb', line 14 def initialize(package_name) @package_name = package_name @cache = nil end |
Instance Method Details
#info ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/resources/npm.rb', line 19 def info return @info if defined?(@info) cmd = inspec.command("npm ls -g --json #{@package_name}") @info = { name: @package_name, type: 'npm', installed: cmd.exit_status == 0, } return @info unless @info[:installed] pkgs = JSON.parse(cmd.stdout) @info[:version] = pkgs['dependencies'][@package_name]['version'] @info end |
#installed? ⇒ Boolean
35 36 37 |
# File 'lib/resources/npm.rb', line 35 def installed? info[:installed] == true end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/resources/npm.rb', line 43 def to_s "Npm Package #{@package_name}" end |
#version ⇒ Object
39 40 41 |
# File 'lib/resources/npm.rb', line 39 def version info[:version] end |