Class: Inspec::Resources::GemPackage
- Inherits:
-
Object
- Object
- Inspec::Resources::GemPackage
- Defined in:
- lib/inspec/resources/gem.rb
Instance Attribute Summary collapse
-
#gem_binary ⇒ Object
readonly
Returns the value of attribute gem_binary.
Instance Method Summary collapse
- #info ⇒ Object
-
#initialize(package_name, gem_binary = nil) ⇒ GemPackage
constructor
A new instance of GemPackage.
- #installed? ⇒ Boolean
- #to_s ⇒ Object
- #version ⇒ Object
-
#versions ⇒ Object
this returns an array of strings.
Constructor Details
#initialize(package_name, gem_binary = nil) ⇒ GemPackage
Returns a new instance of GemPackage.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/inspec/resources/gem.rb', line 18 def initialize(package_name, gem_binary = nil) @package_name = package_name @gem_binary = case gem_binary when nil "gem" when :chef if inspec.os.windows? 'c:\opscode\chef\embedded\bin\gem.bat' else "/opt/chef/embedded/bin/gem" end when :chef_server "/opt/opscode/embedded/bin/gem" else gem_binary end skip_resource "Unable to retrieve gem information" if info.empty? end |
Instance Attribute Details
#gem_binary ⇒ Object (readonly)
Returns the value of attribute gem_binary.
16 17 18 |
# File 'lib/inspec/resources/gem.rb', line 16 def gem_binary @gem_binary end |
Instance Method Details
#info ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/inspec/resources/gem.rb', line 37 def info return @info if defined?(@info) cmd = inspec.command("#{@gem_binary} list --local -a -q \^#{@package_name}\$") return {} unless cmd.exit_status == 0 # extract package name and version # parses data like winrm (1.3.4, 1.3.3) params = /^\s*([^\(]*?)\s*\((.*?)\)\s*$/.match(cmd.stdout.chomp) @info = { installed: !params.nil?, type: "gem", } return @info unless @info[:installed] versions = params[2].split(",").map(&:strip) @info[:name] = params[1] @info[:version] = versions[0] @info[:versions] = versions @info end |
#installed? ⇒ Boolean
59 60 61 |
# File 'lib/inspec/resources/gem.rb', line 59 def installed? info[:installed] == true end |
#to_s ⇒ Object
72 73 74 |
# File 'lib/inspec/resources/gem.rb', line 72 def to_s "gem package #{@package_name}" end |
#version ⇒ Object
63 64 65 |
# File 'lib/inspec/resources/gem.rb', line 63 def version info[:version] end |
#versions ⇒ Object
this returns an array of strings
68 69 70 |
# File 'lib/inspec/resources/gem.rb', line 68 def versions info[:versions] end |