Class: Inspec::Resources::NpmPackage
- Inherits:
-
Object
- Object
- Inspec::Resources::NpmPackage
- Defined in:
- lib/resources/npm.rb
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.
15 16 17 18 |
# File 'lib/resources/npm.rb', line 15 def initialize(package_name) @package_name = package_name @cache = nil end |
Instance Method Details
#info ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/resources/npm.rb', line 20 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
36 37 38 |
# File 'lib/resources/npm.rb', line 36 def installed? info[:installed] == true end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/resources/npm.rb', line 44 def to_s "Npm Package #{@package_name}" end |
#version ⇒ Object
40 41 42 |
# File 'lib/resources/npm.rb', line 40 def version info[:version] end |