Class: Chef::Provider::Package::Yum::RPMPackage

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/chef/provider/package/yum/rpm_utils.rb

Direct Known Subclasses

RPMDbPackage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RPMPackage

Returns a new instance of RPMPackage.


326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 326

def initialize(*args)
  if args.size == 4
    @n = args[0]
    @version = RPMVersion.new(args[1])
    @a = args[2]
    @provides = args[3]
  elsif args.size == 6
    @n = args[0]
    e = args[1].to_i
    v = args[2]
    r = args[3]
    @version = RPMVersion.new(e, v, r)
    @a = args[4]
    @provides = args[5]
  else
    raise ArgumentError, "Expecting either 'name, epoch-version-release, arch, provides' " \
      "or 'name, epoch, version, release, arch, provides'"
  end

  # We always have one, ourselves!
  if @provides.empty?
    @provides = [ RPMProvide.new(@n, @version.evr, :==) ]
  end
end

Instance Attribute Details

#aObject (readonly) Also known as: arch

Returns the value of attribute a


350
351
352
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 350

def a
  @a
end

#nObject (readonly) Also known as: name

Returns the value of attribute n


350
351
352
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 350

def n
  @n
end

#providesObject (readonly)

Returns the value of attribute provides


350
351
352
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 350

def provides
  @provides
end

#versionObject (readonly)

Returns the value of attribute version


350
351
352
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 350

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object


354
355
356
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 354

def <=>(other)
  compare(other)
end

#compare(y) ⇒ Object


358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 358

def compare(y)
  x = self

  # easy! :)
  return 0 if x.nevra == y.nevra

  # compare name
  if x.n.nil? == false && y.n.nil?
    return 1
  elsif x.n.nil? && y.n.nil? == false
    return -1
  elsif x.n.nil? == false && y.n.nil? == false
    if x.n < y.n
      return -1
    elsif x.n > y.n
      return 1
    end
  end

  # compare version
  if x.version > y.version
    return 1
  elsif x.version < y.version
    return -1
  end

  # compare arch
  if x.a.nil? == false && y.a.nil?
    return 1
  elsif x.a.nil? && y.a.nil? == false
    return -1
  elsif x.a.nil? == false && y.a.nil? == false
    if x.a < y.a
      return -1
    elsif x.a > y.a
      return 1
    end
  end

  0
end

#nevraObject


404
405
406
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 404

def nevra
  "#{@n}-#{@version.evr}.#{@a}"
end

#to_sObject


400
401
402
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 400

def to_s
  nevra
end