Class: Inspec::Resources::GemPackage
- Inherits:
-
Object
- Object
- Inspec::Resources::GemPackage
- Defined in:
- lib/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
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/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/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 |
# File 'lib/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.zero? # 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(',') @info[:name] = params[1] @info[:version] = versions[0] @info end |
#installed? ⇒ Boolean
58 59 60 |
# File 'lib/resources/gem.rb', line 58 def installed? info[:installed] == true end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/resources/gem.rb', line 66 def to_s "gem package #{@package_name}" end |
#version ⇒ Object
62 63 64 |
# File 'lib/resources/gem.rb', line 62 def version info[:version] end |