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

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

Direct Known Subclasses

RPMDbPackage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RPMPackage

Returns a new instance of RPMPackage.



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/chef/provider/package/yum.rb', line 336

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.



360
361
362
# File 'lib/chef/provider/package/yum.rb', line 360

def a
  @a
end

#nObject (readonly) Also known as: name

Returns the value of attribute n.



360
361
362
# File 'lib/chef/provider/package/yum.rb', line 360

def n
  @n
end

#providesObject (readonly)

Returns the value of attribute provides.



360
361
362
# File 'lib/chef/provider/package/yum.rb', line 360

def provides
  @provides
end

#versionObject (readonly)

Returns the value of attribute version.



360
361
362
# File 'lib/chef/provider/package/yum.rb', line 360

def version
  @version
end

Instance Method Details

#<=>(y) ⇒ Object



364
365
366
# File 'lib/chef/provider/package/yum.rb', line 364

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

#compare(y) ⇒ Object



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
399
400
401
402
403
404
405
406
407
408
# File 'lib/chef/provider/package/yum.rb', line 368

def compare(y)
  x = self

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

  # compare name
  if x.n.nil? == false and y.n.nil?
    return 1
  elsif x.n.nil? and y.n.nil? == false
    return -1
  elsif x.n.nil? == false and 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 and y.a.nil?
    return 1
  elsif x.a.nil? and y.a.nil? == false
    return -1
  elsif x.a.nil? == false and y.a.nil? == false
    if x.a < y.a
      return -1
    elsif x.a > y.a
      return 1
    end
  end

  return 0
end

#nevraObject



414
415
416
# File 'lib/chef/provider/package/yum.rb', line 414

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

#to_sObject



410
411
412
# File 'lib/chef/provider/package/yum.rb', line 410

def to_s
  nevra
end