Class: Dobby::Package
- Inherits:
-
Object
- Object
- Dobby::Package
- Defined in:
- lib/dobby/package.rb
Overview
A Package describes a particular Debian package installation. Dobby::Package is adapted from Debian::Deb and Debian::Field source: https://anonscm.debian.org/cgit/pkg-ruby-extras/ruby-debian.git/tree/lib/debian.rb
Defined Under Namespace
Classes: FieldRequiredError
Constant Summary collapse
- MAX_VERSION =
MaxVersion is a special value which is always sorted first.
'|MAX|'
- MIN_VERSION =
MinVersion is a special value which is always sorted last.
'|MIN|'
Instance Attribute Summary collapse
-
#arch ⇒ Object
readonly
Returns the value of attribute arch.
-
#dist ⇒ Object
readonly
Returns the value of attribute dist.
-
#multiarch ⇒ Object
readonly
Returns the value of attribute multiarch.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#!=(other) ⇒ Boolean
True if self === other and self.version does not equal other.version.
-
#<(other) ⇒ Boolean
True if self === other and self.version is less than other.version.
-
#<=(other) ⇒ Boolean
True if self === other and self.version is less than or equal to other.version.
-
#==(other) ⇒ Boolean
True if self === other and self.version equals other.version.
-
#===(other) ⇒ Boolean
True if other is present and other.package is the same as self.package.
-
#>(other) ⇒ Boolean
True if self === other and self.version is greater than other.version.
-
#>=(other) ⇒ Boolean
True if self === other and self.version is greater than or equal to other.version.
-
#apt_name ⇒ Object
When a package has multiarch set to same, dpkg and apt will know of it by a name such as 'libquadmath0:amd64' instead of 'libquadmath0'.
-
#compare_to(other) ⇒ Integer
This method is wrapped by the standard comparison operators, but is provided for cases where it is not practical to compare two Package objects.
-
#filtered?(other, filter = :default) ⇒ Boolean
Compared to some other Package, should this Package be filtered from results?.
-
#initialize(name:, version:, release:, dist: nil, arch: nil, source: nil, target: nil, multiarch: nil) ⇒ Package
constructor
Set up a new Debian Package.
-
#target_at_least?(version) ⇒ Boolean
True if the target version meets or exceeds the provided package version.
-
#to_s ⇒ String
String representation of the package.
Constructor Details
#initialize(name:, version:, release:, dist: nil, arch: nil, source: nil, target: nil, multiarch: nil) ⇒ Package
Set up a new Debian Package
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dobby/package.rb', line 39 def initialize(name:, version:, release:, dist: nil, arch: nil, source: nil, target: nil, multiarch: nil) raise FieldRequiredError, 'name' unless name raise FieldRequiredError, 'version' unless version raise FieldRequiredError, 'release' unless release raise FieldRequiredError, 'arch' if arch.nil? && multiarch == 'same' @name = name @version = version @source = source @dist = dist @release = release @arch = arch @target = target @multiarch = multiarch end |
Instance Attribute Details
#arch ⇒ Object (readonly)
Returns the value of attribute arch.
28 29 30 |
# File 'lib/dobby/package.rb', line 28 def arch @arch end |
#dist ⇒ Object (readonly)
Returns the value of attribute dist.
27 28 29 |
# File 'lib/dobby/package.rb', line 27 def dist @dist end |
#multiarch ⇒ Object (readonly)
Returns the value of attribute multiarch.
30 31 32 |
# File 'lib/dobby/package.rb', line 30 def multiarch @multiarch end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/dobby/package.rb', line 23 def name @name end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
25 26 27 |
# File 'lib/dobby/package.rb', line 25 def release @release end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
26 27 28 |
# File 'lib/dobby/package.rb', line 26 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
29 30 31 |
# File 'lib/dobby/package.rb', line 29 def target @target end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
24 25 26 |
# File 'lib/dobby/package.rb', line 24 def version @version end |
Instance Method Details
#!=(other) ⇒ Boolean
Returns True if self === other and self.version does not equal other.version.
139 140 141 |
# File 'lib/dobby/package.rb', line 139 def !=(other) self === other && compare_to(other.version) != 0 end |
#<(other) ⇒ Boolean
Returns True if self === other and self.version is less than other.version.
107 108 109 |
# File 'lib/dobby/package.rb', line 107 def <(other) self === other && compare_to(other.version) < 0 end |
#<=(other) ⇒ Boolean
Returns True if self === other and self.version is less than or equal to other.version.
114 115 116 |
# File 'lib/dobby/package.rb', line 114 def <=(other) self === other && compare_to(other.version) <= 0 end |
#==(other) ⇒ Boolean
Returns True if self === other and self.version equals other.version.
120 121 122 |
# File 'lib/dobby/package.rb', line 120 def ==(other) self === other && compare_to(other.version).zero? end |
#===(other) ⇒ Boolean
Returns True if other is present and other.package is the same as self.package.
101 102 103 |
# File 'lib/dobby/package.rb', line 101 def ===(other) other && (name == other.name || source == other.name || name == other.source) end |
#>(other) ⇒ Boolean
Returns True if self === other and self.version is greater than other.version.
133 134 135 |
# File 'lib/dobby/package.rb', line 133 def >(other) self === other && compare_to(other.version) > 0 end |
#>=(other) ⇒ Boolean
Returns True if self === other and self.version is greater than or equal to other.version.
127 128 129 |
# File 'lib/dobby/package.rb', line 127 def >=(other) self === other && compare_to(other.version) >= 0 end |
#apt_name ⇒ Object
When a package has multiarch set to same, dpkg and apt will know of it by a name such as 'libquadmath0:amd64' instead of 'libquadmath0'. In these cases, return the name alongside the architecture to make it easier to act on results.
59 60 61 62 63 |
# File 'lib/dobby/package.rb', line 59 def apt_name return name unless multiarch == 'same' "#{name}:#{arch}" end |
#compare_to(other) ⇒ Integer
This method is wrapped by the standard comparison operators, but is provided for cases where it is not practical to compare two Package objects.
148 149 150 151 152 153 154 |
# File 'lib/dobby/package.rb', line 148 def compare_to(other) return 0 if version == other return -1 if version == MIN_VERSION || other == MAX_VERSION return 1 if version == MAX_VERSION || other == MIN_VERSION Debian::AptPkg.cmp_version(version, other) end |
#filtered?(other, filter = :default) ⇒ Boolean
Compared to some other Dobby::Package, should this Package be filtered from results?
If filter is set to :default, return true if releases do not match or if my version is at least the other package's version.
If filter is set to :target, addtionally return true if my target version is at least the other's version.
77 78 79 80 81 82 83 |
# File 'lib/dobby/package.rb', line 77 def filtered?(other, filter = :default) return true if release != other.release || self >= other return target_at_least?(other) if filter == :target return false if filter == :default raise UnknownFilterError, filter end |
#target_at_least?(version) ⇒ Boolean
Returns True if the target version meets or exceeds the provided package version.
94 95 96 |
# File 'lib/dobby/package.rb', line 94 def target_at_least?(version) !target.nil? && version.compare_to(target.to_s) <= 0 end |
#to_s ⇒ String
Returns String representation of the package.
86 87 88 |
# File 'lib/dobby/package.rb', line 86 def to_s "#{apt_name} #{version}" end |