class Schmersion::VersionCalculator
Public Class Methods
new(current, commits, **options)
click to toggle source
# File lib/schmersion/version_calculator.rb, line 8 def initialize(current, commits, **options) if current.is_a?(String) current = Semantic::Version.new(current) end @current = current || Semantic::Version.new('1.0.0') @commits = commits @options = options end
Public Instance Methods
calculate()
click to toggle source
# File lib/schmersion/version_calculator.rb, line 18 def calculate if @current.pre && pre? new_version = @current.dup elsif breaking_changes? && consider_breaking_changes_major? && @current.major.positive? new_version = @current.increment!(:major) elsif features? || breaking_changes? new_version = @current.increment!(:minor) else new_version = @current.increment!(:patch) end add_pre_to_version(new_version) if @options[:pre] new_version end
Private Instance Methods
add_pre_to_version(version)
click to toggle source
# File lib/schmersion/version_calculator.rb, line 54 def add_pre_to_version(version) prefix = @options[:pre] prefix = 'pre' unless prefix.is_a?(String) current_prefix, current_sequence = @current&.pre&.split('.', 2) if current_prefix == prefix # If the current version's prefix is the same as the one # that's been selected, we'll increment its integer pre_sequence = current_sequence.to_i + 1 else pre_sequence = 1 end version.pre = "#{prefix}.#{pre_sequence}" version end
breaking_changes?()
click to toggle source
# File lib/schmersion/version_calculator.rb, line 44 def breaking_changes? @commits.any? { |c| c.message.breaking_change? } end
consider_breaking_changes_major?()
click to toggle source
# File lib/schmersion/version_calculator.rb, line 48 def consider_breaking_changes_major? return false if @options[:breaking_change_not_major] true end
features?()
click to toggle source
# File lib/schmersion/version_calculator.rb, line 40 def features? @commits.any? { |c| c.message.type == 'feat' } end
pre?()
click to toggle source
# File lib/schmersion/version_calculator.rb, line 36 def pre? !!@options[:pre] end