Class: ThorSCMVersion::Prerelease
- Inherits:
-
Object
- Object
- ThorSCMVersion::Prerelease
- Defined in:
- lib/thor-scmversion/prerelease.rb
Constant Summary collapse
- TYPE_FORMAT =
/[A-Za-z0-9]+/
- FORMAT =
/(#{TYPE_FORMAT})\.(\d+)/.freeze
- DEFAULT_TYPE =
'alpha'
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.from_string(str) ⇒ Prerelease
Reads the prerelease segment of the version.
Instance Method Summary collapse
- #<(other) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
-
#initialize(type = DEFAULT_TYPE, version = 1) ⇒ Prerelease
constructor
initialize.
-
#method_missing(method, *args, &blk) ⇒ Object
Delegate methods to @version so this object acts like an Integer.
- #to_s ⇒ Object
Constructor Details
#initialize(type = DEFAULT_TYPE, version = 1) ⇒ Prerelease
initialize
Examples:
'beta', 1 #=> x.x.x-beta.1
39 40 41 42 |
# File 'lib/thor-scmversion/prerelease.rb', line 39 def initialize(type = DEFAULT_TYPE, version = 1) @version = version.to_i @type = type.nil? || type.empty? ? DEFAULT_TYPE : type end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
Delegate methods to @version so this object acts like an Integer
75 76 77 78 |
# File 'lib/thor-scmversion/prerelease.rb', line 75 def method_missing(method, *args, &blk) @version = self.version.send(method, *args, &blk) self end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
30 31 32 |
# File 'lib/thor-scmversion/prerelease.rb', line 30 def type @type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
29 30 31 |
# File 'lib/thor-scmversion/prerelease.rb', line 29 def version @version end |
Class Method Details
.from_string(str) ⇒ Prerelease
Reads the prerelease segment of the version. While semver provides a more general format, the format with thor-scmversion is more strictly defined:
Examples:
str = 'alpha.1'
str = 'beta.10'
str = 'rc.2'
19 20 21 22 23 24 25 26 |
# File 'lib/thor-scmversion/prerelease.rb', line 19 def from_string(str) return nil if str.nil? matchdata = str.match(FORMAT) type, version = matchdata.captures unless matchdata.nil? raise InvalidPrereleaseFormatError.new(str) if (matchdata.nil? || matchdata.captures.size != 2) new(type, version) end |
Instance Method Details
#<(other) ⇒ Object
62 63 64 65 |
# File 'lib/thor-scmversion/prerelease.rb', line 62 def <(other) raise ArgumentError unless kind_of? other.class return (self <=> other) == -1 end |
#<=>(other) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/thor-scmversion/prerelease.rb', line 48 def <=>(other) raise ArgumentError unless kind_of? other.class if self.type == other.type self.version <=> other.version else self.type <=> other.type end end |
#==(other) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/thor-scmversion/prerelease.rb', line 67 def ==(other) other && kind_of?(other.class) && self.version == other.version && self.type == other.type end |
#>(other) ⇒ Object
57 58 59 60 |
# File 'lib/thor-scmversion/prerelease.rb', line 57 def >(other) raise ArgumentError unless kind_of? other.class return (self <=> other) == 1 end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/thor-scmversion/prerelease.rb', line 44 def to_s "#{@type}.#{@version}" end |