Sha256: c81b1181a513ec5620b447e3458e0295868698a3107fb7c4b9680ce313a5b14b

Contents?: true

Size: 862 Bytes

Versions: 3

Compression:

Stored size: 862 Bytes

Contents

require 'serverspec'
require 'serverspec/type/base'

module Serverspec::Type
  class NpmPackage < Base

    def initialize(name)
      @name = name
      @runner = Specinfra::Runner
    end

    def installed?(provider, version)
      command_result = @runner.run_command("npm list -g #{name}")

      software = command_result.stdout.split("\n").each_with_object({}) do |s, h|
        if s.include? "@"
          package_name, package_version = s.split('@')
          package_name = package_name.gsub(/.*? /, '')
          h[String(package_name).strip.downcase] = String(package_version).strip.downcase
        end
        h
      end

      if (version.nil?)
        !software[name.downcase].nil?
      else
        software[name.downcase] == version
      end
    end
  end

  def npm_package(name)
    NpmPackage.new(name)
  end
end

include Serverspec::Type

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
octopus-serverspec-extensions-0.19.1 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.19.0 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.14.0 lib/octopus_serverspec_extensions/type/npm_package.rb