Sha256: e1d3d814100ac2a57118f50b5aff0fecb2edf4bb1dd0718a9e81e8d79f06f65b

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

module New::Version
  require 'semantic'

  def part; @part; end
  def previous_version; @previous_version; end
  def version; @version; end

  def bump_version previous_version, part = nil
    @previous_version = get_version previous_version
    @part = part ||= get_part

    # bump version
    case part
    when :major
      @previous_version.major += 1
      @previous_version.minor = 0
      @previous_version.patch = 0
    when :minor
      @previous_version.minor += 1
      @previous_version.patch = 0
    when :patch
      @previous_version.patch += 1
    end

    # set new version
    @version = @previous_version
  end

private

  def get_part
    New.say "            Current Version: #{previous_version}", type: :success
    New.say " Specify which part to bump: [#{'Mmp'.green}] (#{'M'.green}ajor / #{'m'.green}inor / #{'p'.green}atch)"
    part = STDIN.gets.chomp!

    case part
    when 'M'
      :major
    when 'm'
      :minor
    when 'p'
      :patch
    end
  end

  def get_version version
    begin
      Semantic::Version.new version.to_s
    rescue
      New.say "#{version} is not a semantic version.  Use format `1.2.3`", type: :fail
      exit
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
new-0.1.1 lib/new/version.rb
new-0.0.15 lib/new/version.rb
new-0.0.14 lib/new/version.rb
new-0.0.13 lib/new/version.rb
new-0.0.12 lib/new/version.rb