From 508a6889d11d8a0296ba567d9c079bb0c5dabf7c Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Thu, 17 Sep 2015 16:43:10 +0200 Subject: [PATCH] align npm resource with info handling Signed-off-by: Dominik Richter --- lib/resources/npm.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/resources/npm.rb b/lib/resources/npm.rb index 0da4f7663..69a2e8033 100644 --- a/lib/resources/npm.rb +++ b/lib/resources/npm.rb @@ -13,23 +13,26 @@ class NpmPackage < Vulcano.resource(1) end def info - return @cache if !@cache.nil? + return @info unless @info.nil? + cmd = vulcano.run_command("npm ls -g --json #{@package_name}") - return nil if cmd.exit_status != 0 - pkgs = JSON.parse(cmd.stdout) - @cache = { + @info = { name: @package_name, - version: pkgs['dependencies'][@package_name]['version'], type: 'npm', + installed: cmd.exit_status != 0, } + return @info unless @info[:installed] + + pkgs = JSON.parse(cmd.stdout) + @info[version] = pkgs['dependencies'][@package_name]['version'] end def installed? - !info.nil? + info[:installed] end def version - info.nil? ? nil : info[:version] + info[:version] end def to_s