Refactor and document PkgVersion
.
This commit is contained in:
parent
72419630b4
commit
425cc76da9
@ -2,24 +2,22 @@
|
|||||||
|
|
||||||
require "version"
|
require "version"
|
||||||
|
|
||||||
|
# Combination of a version and a revision.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
class PkgVersion
|
class PkgVersion
|
||||||
include Comparable
|
include Comparable
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
|
|
||||||
RX = /\A(.+?)(?:_(\d+))?\z/.freeze
|
REGEX = /\A(.+?)(?:_(\d+))?\z/.freeze
|
||||||
|
private_constant :REGEX
|
||||||
|
|
||||||
attr_reader :version, :revision
|
attr_reader :version, :revision
|
||||||
|
|
||||||
delegate [ # rubocop:disable Layout/HashAlignment
|
delegate [:major, :minor, :patch, :major_minor, :major_minor_patch] => :version
|
||||||
:major,
|
|
||||||
:minor,
|
|
||||||
:patch,
|
|
||||||
:major_minor,
|
|
||||||
:major_minor_patch,
|
|
||||||
] => :version
|
|
||||||
|
|
||||||
def self.parse(path)
|
def self.parse(path)
|
||||||
_, version, revision = *path.match(RX)
|
_, version, revision = *path.match(REGEX)
|
||||||
version = Version.create(version)
|
version = Version.create(version)
|
||||||
new(version, revision.to_i)
|
new(version, revision.to_i)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user