Sha256: a59a6434fa4ac899f01cc5c699d5bdca00e14da2af46568eec55bf635d94aaa7

Contents?: true

Size: 898 Bytes

Versions: 41

Compression:

Stored size: 898 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

41 entries across 41 versions & 1 rubygems

Version Path
octopus-serverspec-extensions-0.18.1 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.18.0 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.17.3 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.17.2 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.17.1 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.17.0 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.15.5 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.15.4 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.15.3 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.15.2 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.15.1 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.15.0 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.13.6 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.13.5 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.13.4 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.13.3 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.13.2 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.13.1 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.13.0 lib/octopus_serverspec_extensions/type/npm_package.rb
octopus-serverspec-extensions-0.12.2 lib/octopus_serverspec_extensions/type/npm_package.rb