class VersionRecord::Version
Attributes
major[RW]
minor[RW]
patch[RW]
Public Class Methods
new(version)
click to toggle source
# File lib/version_record/version.rb, line 7 def initialize(version) @major, @minor, @patch, @prerelease = Parser.new(version.to_s).parse end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/version_record/version.rb, line 28 def <=>(other) return unless other.respond_to?(:to_version) other = other.to_version if same_segments?(other, :major, :minor, :patch, :prerelease) 0 elsif same_segments?(other, :major, :minor, :patch) compare_by(other, :prerelease) elsif same_segments?(other, :major, :minor) compare_by(other, :patch) elsif same_segments?(other, :major) compare_by(other, :minor) else compare_by(other, :major) end end
bump(segment = :minor)
click to toggle source
# File lib/version_record/version.rb, line 19 def bump(segment = :minor) send("bump_#{segment}") if [:major, :minor, :patch].include?(segment) self end
prerelease()
click to toggle source
# File lib/version_record/version.rb, line 24 def prerelease @prerelease.name if @prerelease end
to_s()
click to toggle source
# File lib/version_record/version.rb, line 11 def to_s "#{@major}.#{@minor}.#{@patch}#{@prerelease}" end
to_version()
click to toggle source
# File lib/version_record/version.rb, line 15 def to_version self end
Private Instance Methods
bump_major()
click to toggle source
# File lib/version_record/version.rb, line 47 def bump_major @major += 1 @minor = @patch = 0 end
bump_minor()
click to toggle source
# File lib/version_record/version.rb, line 52 def bump_minor @minor += 1 @patch = 0 end
bump_patch()
click to toggle source
# File lib/version_record/version.rb, line 57 def bump_patch @patch += 1 end
compare_by(other, segment)
click to toggle source
# File lib/version_record/version.rb, line 72 def compare_by(other, segment) if [:major, :minor, :patch].include?(segment) send(segment) <=> other.send(segment) else compare_by_prerelease(other) end end
compare_by_prerelease(other)
click to toggle source
# File lib/version_record/version.rb, line 80 def compare_by_prerelease(other) return 1 if @prerelease.nil? && other.prerelease return -1 if @prerelease && other.prerelease.nil? @prerelease <=> Prerelease.build(other.prerelease) end
same_segments?(other, *segments)
click to toggle source
Checks if all the segments in other are equal to the ones passed as a parameter.
For example, calling same_segments?(other, :major, :minor) will check:
self.major == other.major && self.minor == other.minor
# File lib/version_record/version.rb, line 68 def same_segments?(other, *segments) segments.all? { |segment| send(segment) == other.send(segment) } end