Bake::GemSourceBakeGemVersion

class Version

Represents a gem version with support for parsing and incrementing version numbers.

Definitions

def self.update_version(line)

If the line contains a version constant, update it using the provided block.

Implementation

def self.update_version(line)
	if match = line.match(LINE_PATTERN)
		parts = match[:parts].split(/\./).map(&:to_i)
		suffix = match[:suffix]
		
		version = self.new(parts, suffix)
		
		yield version
		
		line.sub!(match[:version], version.join)
	end
end

def initialize(parts, suffix)

Initialize a new version with the given parts and optional suffix.

Signature

parameter parts Array(Integer)

The version number parts (e.g., [1, 2, 3] for "1.2.3").

parameter suffix String | Nil

The optional version suffix (e.g., "alpha", "beta").

Implementation

def initialize(parts, suffix)
	@parts = parts
	@suffix = suffix
end

def release?

Check if this version represents a release version.

Signature

returns Boolean

True if the version has no suffix, indicating it's a release version.

Implementation

def release?
	@suffix.nil?
end

def join

Join all parts together to form a version string.

Implementation

def join
	if @suffix
		return "#{@parts.join('.')}-#{@suffix}"
	else
		return @parts.join(".")
	end
end

def to_s

The version string with a "v" prefix.

Implementation

def to_s
	"v#{join}"
end

def increment(bump)

Increment the version according to the provided bump specification.

Signature

parameter bump Array(Integer | Nil)

Array specifying how to increment each version part.

returns Version

Self, for method chaining.

Implementation

def increment(bump)
	bump.each_with_index do |increment, index|
		if index > @parts.size
			@suffix = bump[index..].join(".")
			break
		end
		
		if increment == 1
			@parts[index] += 1
		elsif increment == 0
			@parts[index] = 0
		end
		# If increment is nil, we don't change that part of the version
	end
	
	return self
end