Class: Schmersion::VersionCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/schmersion/version_calculator.rb

Instance Method Summary collapse

Constructor Details

#initialize(current, commits, **options) ⇒ VersionCalculator

Returns a new instance of VersionCalculator.



8
9
10
11
12
13
14
15
16
# 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

Instance Method Details

#calculateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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