Class: Inspec::Resources::YumRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/yum.rb

Instance Method Summary collapse

Constructor Details

#initialize(yum, reponame) ⇒ YumRepo

Returns a new instance of YumRepo.



112
113
114
115
# File 'lib/inspec/resources/yum.rb', line 112

def initialize(yum, reponame)
  @yum = yum
  @reponame = reponame
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


136
137
138
139
140
# File 'lib/inspec/resources/yum.rb', line 136

def enabled?
  return false unless exist?

  info["status"] == "enabled"
end

#exist?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/inspec/resources/yum.rb', line 132

def exist?
  !info.empty?
end

#infoObject



124
125
126
127
128
129
130
# File 'lib/inspec/resources/yum.rb', line 124

def info
  return @cache if defined?(@cache)

  selection = @yum.repositories.select { |e| e["id"] == @reponame || shortname(e["id"]) == @reponame }
  @cache = selection.empty? ? {} : selection.first
  @cache
end

#shortname(id) ⇒ Object

extracts the shortname from a repo id e.g. extras/7/x86_64 -> extras



119
120
121
122
# File 'lib/inspec/resources/yum.rb', line 119

def shortname(id)
  val = %r{^\s*([^/]*?)/(.*?)\s*$}.match(id)
  val.nil? ? nil : val[1]
end

#to_sObject



158
159
160
# File 'lib/inspec/resources/yum.rb', line 158

def to_s
  "YumRepo #{@reponame}"
end