Class: Chef::Provider::Package::Yum::RPMDependency

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

Overview

Simple implementation from rpm and ruby-rpm reference code

Direct Known Subclasses

RPMProvide, RPMRequire

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RPMDependency

Returns a new instance of RPMDependency.



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/chef/provider/package/yum.rb', line 418

def initialize(*args)
  if args.size == 3
    @name = args[0]
    @version = RPMVersion.new(args[1])
    # Our requirement to other dependencies
    @flag = args[2] || :==
  elsif args.size == 5
    @name = args[0]
    e = args[1].to_i
    v = args[2]
    r = args[3]
    @version = RPMVersion.new(e,v,r)
    @flag = args[4] || :==
  else
    raise ArgumentError, "Expecting either 'name, epoch-version-release, flag' or " +
                         "'name, epoch, version, release, flag'"
  end
end

Instance Attribute Details

#flagObject (readonly)

Returns the value of attribute flag.



436
437
438
# File 'lib/chef/provider/package/yum.rb', line 436

def flag
  @flag
end

#nameObject (readonly)

Returns the value of attribute name.



436
437
438
# File 'lib/chef/provider/package/yum.rb', line 436

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



436
437
438
# File 'lib/chef/provider/package/yum.rb', line 436

def version
  @version
end

Class Method Details

.parse(string) ⇒ Object

Parses 2 forms:

“mtr >= 2:0.71-3.0” “mta”



442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/chef/provider/package/yum.rb', line 442

def self.parse(string)
  if string =~ %r{^(\S+)\s+(>|>=|=|==|<=|<)\s+(\S+)$}
    name = $1
    if $2 == "="
      flag = :==
    else
      flag = :"#{$2}"
    end
    version = $3

    return self.new(name, version, flag)
  else
    name = string
    return self.new(name, nil, nil)
  end
end

Instance Method Details

#satisfy?(y) ⇒ Boolean

Test if another RPMDependency satisfies our requirements

Returns:

  • (Boolean)


460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/chef/provider/package/yum.rb', line 460

def satisfy?(y)
  unless y.kind_of?(RPMDependency)
    raise ArgumentError, "Expecting an RPMDependency object"
  end

  x = self

  # Easy!
  if x.name != y.name
    return false
  end

  # Partial compare
  #
  # eg: x.version 2.3 == y.version 2.3-1
  sense = x.version.partial_compare(y.version)

  # Thanks to rpmdsCompare() rpmds.c
  if sense < 0 and (x.flag == :> || x.flag == :>=) || (y.flag == :<= || y.flag == :<)
    return true
  elsif sense > 0 and (x.flag == :< || x.flag == :<=) || (y.flag == :>= || y.flag == :>)
    return true
  elsif sense == 0 and (
    ((x.flag == :== or x.flag == :<= or x.flag == :>=) and (y.flag == :== or y.flag == :<= or y.flag == :>=)) or
    (x.flag == :< and y.flag == :<) or
    (x.flag == :> and y.flag == :>)
  )
    return true
  end

  return false
end