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

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/provider/package/yum/rpm_utils.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.



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 411

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.



429
430
431
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 429

def flag
  @flag
end

#nameObject (readonly)

Returns the value of attribute name.



429
430
431
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 429

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



429
430
431
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 429

def version
  @version
end

Class Method Details

.parse(string) ⇒ Object

Parses 2 forms:

"mtr >= 2:0.71-3.0" "mta"



435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 435

def self.parse(string)
  if /^(\S+)\s+(>|>=|=|==|<=|<)\s+(\S+)$/.match(string) # rubocop:disable Performance/RedundantMatch
    name = $1
    flag = if $2 == "="
             :==
           else
             :"#{$2}"
           end
    version = $3

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

Instance Method Details

#satisfy?(y) ⇒ Boolean

Test if another RPMDependency satisfies our requirements

Returns:

  • (Boolean)


453
454
455
456
457
458
459
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
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 453

def satisfy?(y)
  unless y.is_a?(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) && ((x.flag == :> || x.flag == :>=) || (y.flag == :<= || y.flag == :<))
    return true
  elsif (sense > 0) && ((x.flag == :< || x.flag == :<=) || (y.flag == :>= || y.flag == :>))
    return true
  elsif sense == 0 && (
    ((x.flag == :== || x.flag == :<= || x.flag == :>=) && (y.flag == :== || y.flag == :<= || y.flag == :>=)) ||
    (x.flag == :< && y.flag == :<) ||
    (x.flag == :> && y.flag == :>)
  )
    return true
  end

  false
end