Class: EnhanceRepo::PackageId

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/enhance_repo/package_id.rb

Overview

thin wrapper over rpm package

Direct Known Subclasses

RpmMd::DeltaRpm

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#log

Constructor Details

#initialize(rpmfile) ⇒ PackageId

Returns a new instance of PackageId.



39
40
41
42
43
# File 'lib/enhance_repo/package_id.rb', line 39

def initialize(rpmfile)
  @path = rpmfile
  @rpm = RPM::Package.open(rpmfile)
  @checksum = EnhanceRepo::ConfigOpts.instance.digest_class.hexdigest(File.new(rpmfile).read)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object

Forward other methods



46
47
48
# File 'lib/enhance_repo/package_id.rb', line 46

def method_missing(sym, *args)
  @rpm.send(sym, *args)
end

Instance Attribute Details

#checksumObject

Returns the value of attribute checksum.



33
34
35
# File 'lib/enhance_repo/package_id.rb', line 33

def checksum
  @checksum
end

#pathObject

Returns the value of attribute path.



34
35
36
# File 'lib/enhance_repo/package_id.rb', line 34

def path
  @path
end

#rpmObject

Returns the value of attribute rpm.



35
36
37
# File 'lib/enhance_repo/package_id.rb', line 35

def rpm
  @rpm
end

Instance Method Details

#archObject



58
59
60
61
62
63
64
65
# File 'lib/enhance_repo/package_id.rb', line 58

def arch
  s = self[RPM::TAG_SOURCERPM]
  if s.nil?
    return 'src'
  else
    return @rpm.arch
  end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/enhance_repo/package_id.rb', line 54

def eql?(other)
  @checksum == other.checksum
end

#hashObject



50
51
52
# File 'lib/enhance_repo/package_id.rb', line 50

def hash
  @checksum.hash
end

#identObject



86
87
88
# File 'lib/enhance_repo/package_id.rb', line 86

def ident
  "#{@rpm}.#{@rpm.arch}"
end

#matches(ident) ⇒ Object

match function at name and nvr level



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/enhance_repo/package_id.rb', line 68

def matches(ident)
  # if the name matches, then it is sufficient
  return true if ident == @rpm.name
  # if not, compare the edition without release
  return true if ident == "#{@rpm.name}-#{@rpm.version.v}"
  # if not, compare the edition with release
  return true if ident == "#{@rpm.name}-#{@rpm.version.v}-#{@rpm.version.r}"
  # if not, also the architecture
  return true if ident == "#{@rpm.name}-#{@rpm.version.v}-#{@rpm.version.r}"
  # and finally arch
  return true if ident == "#{@rpm.name}-#{@rpm.version.v}-#{@rpm.version.r}.#{@rpm.arch}"
  false
end

#to_sObject



82
83
84
# File 'lib/enhance_repo/package_id.rb', line 82

def to_s
  @rpm.to_s
end