Class: Prick::PrickVersion
- Inherits:
-
Object
- Object
- Prick::PrickVersion
- Includes:
- Comparable
- Defined in:
- lib/prick/prick_version.rb
Defined Under Namespace
Classes: FormatError
Constant Summary collapse
- PRE_LABEL =
"pre"
- PRE_RE =
/^#{PRE_LABEL}\.(\d+)$/
Instance Attribute Summary collapse
-
#feature ⇒ Object
Returns the value of attribute feature.
-
#fork ⇒ Object
Returns the value of attribute fork.
-
#semver ⇒ Object
Returns the value of attribute semver.
Class Method Summary collapse
-
.parse(name) ⇒ Object
Parse a branch or tag name into a PrickVersion object.
-
.try(version) ⇒ Object
Try converting the string ‘version` into a PrickVersion object.
-
.version?(string) ⇒ Boolean
Return true if ‘string` is a version.
- .zero ⇒ Object
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
def link !feature? or raise Internal, “PrickVersion ##to_s is a feature, not a release” File.join(RELEASE_DIR, to_s) end.
- #clone ⇒ Object
- #dup ⇒ Object
- #eql?(other) ⇒ Boolean
-
#feature? ⇒ Boolean
Return true if this is a feature release.
-
#fork? ⇒ Boolean
Return true if this is a fork release.
- #hash ⇒ Object
-
#increment(part, pre_initial_value = 1) ⇒ Object
‘part` can be one of :major, :minor, :patch, or :pre.
- #increment!(part, pre_initial_value = 1) ⇒ Object
-
#initialize(version, fork: nil, feature: nil) ⇒ PrickVersion
constructor
A new instance of PrickVersion.
-
#inspect ⇒ Object
Render as string.
- #major ⇒ Object
- #major=(major) ⇒ Object
- #minor ⇒ Object
- #minor=(minor) ⇒ Object
- #patch ⇒ Object
- #patch=(patch) ⇒ Object
-
#pre ⇒ Object
The releases is stored as a String (eg. ‘pre.1’) in the semantic version but #pre returns only the Integer number.
-
#pre=(pre) ⇒ Object
#pre= expects an integer or nil argument.
-
#pre? ⇒ Boolean
Return true if this is a pre-release.
- #prerelease ⇒ Object
- #prerelease=(pre) ⇒ Object
- #prerelease? ⇒ Boolean
-
#release? ⇒ Boolean
Return true if this is a release branch (and not a prerelease).
-
#to_s(tag: false) ⇒ Object
Render as branch.
-
#to_tag ⇒ Object
Render as a tag.
- #truncate(part) ⇒ Object
- #zero? ⇒ Boolean
Constructor Details
#initialize(version, fork: nil, feature: nil) ⇒ PrickVersion
Returns a new instance of PrickVersion.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/prick/prick_version.rb', line 64 def initialize(version, fork: nil, feature: nil) case version when String version =~ VERSION_RE or raise PrickVersion::FormatError, "Expected a version, got #{version.inspect}" @fork = fork || $1 @semver = Semantic::Version.new($3) @feature = feature || $4 when Semantic::Version @fork = fork @semver = version.dup @feature = feature when PrickVersion @fork = fork || version.fork @semver = version.semver.dup @feature = feature || version.feature else raise ArgumentError, "Expected a String, PrickVersion, or Semantic::Version, got #{version.class}" end end |
Instance Attribute Details
#feature ⇒ Object
Returns the value of attribute feature.
25 26 27 |
# File 'lib/prick/prick_version.rb', line 25 def feature @feature end |
#fork ⇒ Object
Returns the value of attribute fork.
23 24 25 |
# File 'lib/prick/prick_version.rb', line 23 def fork @fork end |
#semver ⇒ Object
Returns the value of attribute semver.
24 25 26 |
# File 'lib/prick/prick_version.rb', line 24 def semver @semver end |
Class Method Details
.parse(name) ⇒ Object
Parse a branch or tag name into a PrickVersion object. Return a [version, tag] tuple where tag is true if name was a tag
91 92 93 94 95 96 |
# File 'lib/prick/prick_version.rb', line 91 def self.parse(name) name =~ VERSION_RE or raise PrickVersion::FormatError, "Expected a version, got #{name.inspect}" fork, tag, semver, feature = $1, $2, $3, $4 version = PrickVersion.new(semver, fork: fork, feature: feature) [version, tag] end |
.try(version) ⇒ Object
Try converting the string ‘version` into a PrickVersion object. Return nil if unsuccessful
85 86 87 |
# File 'lib/prick/prick_version.rb', line 85 def self.try(version) version.is_a?(PrickVersion) ? version : (version?(version) ? new(version) : nil) end |
.version?(string) ⇒ Boolean
Return true if ‘string` is a version
18 19 20 21 |
# File 'lib/prick/prick_version.rb', line 18 def self.version?(string) string.is_a?(String) or raise Internal, "String expected" !(string =~ VERSION_RE).nil? end |
.zero ⇒ Object
14 |
# File 'lib/prick/prick_version.rb', line 14 def self.zero() PrickVersion.new("0.0.0") end |
Instance Method Details
#<=>(other) ⇒ Object
def link
!feature? or raise Internal, "PrickVersion #{to_s} is a feature, not a release"
File.join(RELEASE_DIR, to_s)
end
139 140 141 142 143 144 145 146 |
# File 'lib/prick/prick_version.rb', line 139 def <=>(other) r = (fork || "") <=> (other.fork || "") return r if r != 0 r = semver <=> other.semver return r if r != 0 r = (feature || "") <=> (other.feature || "") return r end |
#clone ⇒ Object
59 |
# File 'lib/prick/prick_version.rb', line 59 def clone() PrickVersion.new(self) end |
#dup ⇒ Object
58 |
# File 'lib/prick/prick_version.rb', line 58 def dup() PrickVersion.new(self) end |
#eql?(other) ⇒ Boolean
61 |
# File 'lib/prick/prick_version.rb', line 61 def eql?(other) self == other end |
#feature? ⇒ Boolean
Return true if this is a feature release
40 |
# File 'lib/prick/prick_version.rb', line 40 def feature?() !@feature.nil? end |
#fork? ⇒ Boolean
Return true if this is a fork release
37 |
# File 'lib/prick/prick_version.rb', line 37 def fork?() !@fork.nil? end |
#hash ⇒ Object
62 |
# File 'lib/prick/prick_version.rb', line 62 def hash() @semver.hash end |
#increment(part, pre_initial_value = 1) ⇒ Object
‘part` can be one of :major, :minor, :patch, or :pre. If pre is undefined, it is set to `pre_initial_value`
100 101 102 |
# File 'lib/prick/prick_version.rb', line 100 def increment(part, pre_initial_value = 1) self.dup.increment!(part, pre_initial_value) end |
#increment!(part, pre_initial_value = 1) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/prick/prick_version.rb', line 104 def increment!(part, pre_initial_value = 1) if part == :pre self.pre = (self.pre ? self.pre + 1 : pre_initial_value) else @semver = semver.increment!(part) end self end |
#inspect ⇒ Object
Render as string
157 |
# File 'lib/prick/prick_version.rb', line 157 def inspect() to_s end |
#major ⇒ Object
27 |
# File 'lib/prick/prick_version.rb', line 27 def major() @semver.major end |
#major=(major) ⇒ Object
28 |
# File 'lib/prick/prick_version.rb', line 28 def major=(major) @semver.major = major end |
#minor ⇒ Object
30 |
# File 'lib/prick/prick_version.rb', line 30 def minor() @semver.minor end |
#minor=(minor) ⇒ Object
31 |
# File 'lib/prick/prick_version.rb', line 31 def minor=(minor) @semver.minor = minor end |
#patch ⇒ Object
33 |
# File 'lib/prick/prick_version.rb', line 33 def patch() @semver.patch end |
#patch=(patch) ⇒ Object
34 |
# File 'lib/prick/prick_version.rb', line 34 def patch=(patch) @semver.patch = patch end |
#pre ⇒ Object
The releases is stored as a String (eg. ‘pre.1’) in the semantic version but #pre returns only the Integer number
51 |
# File 'lib/prick/prick_version.rb', line 51 def pre() @semver.pre =~ PRE_RE ? $1.to_i : nil end |
#pre=(pre) ⇒ Object
#pre= expects an integer or nil argument
55 |
# File 'lib/prick/prick_version.rb', line 55 def pre=(pre) @semver.pre = (pre ? "#{PRE_LABEL}.#{pre}" : nil) end |
#pre? ⇒ Boolean
Return true if this is a pre-release
46 |
# File 'lib/prick/prick_version.rb', line 46 def pre?() !@semver.pre.nil? end |
#prerelease ⇒ Object
52 |
# File 'lib/prick/prick_version.rb', line 52 def prerelease() pre end |
#prerelease=(pre) ⇒ Object
56 |
# File 'lib/prick/prick_version.rb', line 56 def prerelease=(pre) self.pre = pre end |
#prerelease? ⇒ Boolean
47 |
# File 'lib/prick/prick_version.rb', line 47 def prerelease?() pre? end |
#release? ⇒ Boolean
Return true if this is a release branch (and not a prerelease)
43 |
# File 'lib/prick/prick_version.rb', line 43 def release?() !feature? && !pre? end |
#to_s(tag: false) ⇒ Object
Render as branch
149 150 151 |
# File 'lib/prick/prick_version.rb', line 149 def to_s(tag: false) (fork ? "#{fork}-" : "") + (tag ? "v" : "") + semver.to_s + (feature ? "_#{feature}" : "") end |
#to_tag ⇒ Object
Render as a tag
154 |
# File 'lib/prick/prick_version.rb', line 154 def to_tag() to_s(tag: true) end |
#truncate(part) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/prick/prick_version.rb', line 113 def truncate(part) case part when :pre v = self.dup v.feature = nil v.pre = nil v when :feature v = self.dup v.feature = nil v else raise NotYet end end |
#zero? ⇒ Boolean
15 |
# File 'lib/prick/prick_version.rb', line 15 def zero?() self == PrickVersion.zero end |