class Codelog::Command::Bump

Constants

CHANGELOG_RELEASES_PATH
CHANGELOG_RELEASE_REGEXP
INITIAL_RELEASE_VERSION
VALID_VERSION_TYPES

Public Class Methods

run(version_type, release_date, options) click to toggle source
# File lib/codelog/command/bump.rb, line 9
def self.run(version_type, release_date, options)
  Codelog::Command::Bump.new.run version_type, release_date, options
end

Public Instance Methods

run(version_type, release_date, options) click to toggle source
# File lib/codelog/command/bump.rb, line 13
def run(version_type, release_date, options)
  unless VALID_VERSION_TYPES.include?(version_type.downcase)
    abort(Codelog::Message::Error.invalid_version_type(version_type))
  end

  if options[:preview]
    Codelog::Command::Preview.run(next_version(version_type), release_date)
  else
    Codelog::Command::Release.run(next_version(version_type), release_date)
  end
end

Private Instance Methods

last_created_changelog() click to toggle source
# File lib/codelog/command/bump.rb, line 41
def last_created_changelog
  released_versions = Dir.glob(File.join(CHANGELOG_RELEASES_PATH, '*.md*')).map do |file_path|
    file_path.gsub(CHANGELOG_RELEASES_PATH, '').gsub('.md', '')
  end.grep(CHANGELOG_RELEASE_REGEXP)

  released_versions.max_by do |version_string|
    Gem::Version.new(version_string)
  end || INITIAL_RELEASE_VERSION
end
next_version(version_type) click to toggle source
# File lib/codelog/command/bump.rb, line 27
def next_version(version_type)
  last_version = last_created_changelog.split('.').map(&:to_i)

  case version_type.downcase
  when 'major'
    last_version = [(last_version[0] + 1), 0, 0]
  when 'minor'
    last_version = [last_version.first, (last_version[1] + 1), 0]
  when 'patch'
    last_version[2] += 1
  end
  last_version.join('.')
end