Class: Serverspec::Type::Package

Inherits:
Base
  • Object
show all
Defined in:
lib/serverspec/type/package.rb

Defined Under Namespace

Classes: Version

Instance Method Summary collapse

Methods inherited from Base

#initialize, #to_ary, #to_s

Constructor Details

This class inherits a constructor from Serverspec::Type::Base

Instance Method Details

#installed?(provider, version) ⇒ Boolean

Returns:

  • (Boolean)

4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/serverspec/type/package.rb', line 4

def installed?(provider, version)
  if provider.nil?
    backend.check_installed(@name, version)
  else
    check_method = "check_installed_by_#{provider}".to_sym

    unless backend.respond_to?(check_method) || commands.respond_to?(check_method)
      raise ArgumentError.new("`be_installed` matcher doesn't support #{provider}")
    end

    backend.send(check_method, @name, version)
  end
end

#versionObject


18
19
20
21
22
23
24
25
# File 'lib/serverspec/type/package.rb', line 18

def version
  ret = backend.run_command(commands.get_package_version(@name))[:stdout].strip
  if ret.empty?
    nil
  else
    Version.new(ret)
  end
end