class Bump::Application

The application

Public Class Methods

new(options, help, version, file, logger, command = nil) click to toggle source

@param [Hash] options The cli options @param [String] help The help message @param [String] version The version expression of this command @param [String] file The file name of bump info file @param [Bump::Logger] logger The logger @param [Bump::Command] logger The command executer

# File lib/bump/application.rb, line 12
def initialize(options, help, version, file, logger, command = nil)
  @options = options
  @help = help
  @version = version
  @file = file
  @logger = logger
  @command = command
  @command = Bump::Command.new @logger if @command.nil?
end

Public Instance Methods

action_bump() click to toggle source

The bump action @return [Boolean] true iff success

# File lib/bump/application.rb, line 158
def action_bump
  bump_info = create_bump_info

  return false if bump_info.nil?

  print_bump_plan bump_info

  unless bump_info.valid?
    print_invalid_bump_info bump_info

    return false
  end

  bump_info.perform_update

  report bump_info

  save_bump_info bump_info

  commit_and_tag bump_info if @options[:commit]

  true
end
action_help() click to toggle source

handler of ‘bmp –help`

@return [void]

# File lib/bump/application.rb, line 55
def action_help
  log @help

  true
end
action_info() click to toggle source

handler of ‘bmp [–info]`

@return [void]

# File lib/bump/application.rb, line 124
def action_info
  bump_info = create_bump_info

  return false if bump_info.nil?

  print_version_patterns bump_info

  bump_info.valid?
end
action_version() click to toggle source

handler of ‘bmp –version`

@return [void]

# File lib/bump/application.rb, line 46
def action_version
  log @version

  true
end
bump_level() click to toggle source

Gets the requested bump level. @return [Symbol]

# File lib/bump/application.rb, line 184
def bump_level
  return :major if @options[:major]
  return :minor if @options[:minor]
  return :patch if @options[:patch]
end
bump_option?(options) click to toggle source

Returns true iff it’s a bump option. @param [Hash] options The options

# File lib/bump/application.rb, line 39
def bump_option?(options)
  options[:major] || options[:minor] || options[:patch] || options[:commit] || options[:preid] || options[:release]
end
commit_and_tag(bump_info) click to toggle source

Commits current changes and tag it by the current version. @param [Bump::BumpInfo] bump_info The bump info

# File lib/bump/application.rb, line 241
def commit_and_tag(bump_info)
  @logger.log '===> executing commands'
  @command.exec 'git add .'
  @command.exec "git commit -m '#{bump_info.commit_message}'"
  @command.exec "git tag v#{bump_info.after_version}"
end
create_bump_info() click to toggle source

Gets the bump info @private @return [Bump::BumpInfo]

# File lib/bump/application.rb, line 64
def create_bump_info
  repo = BumpInfoRepository.new @file

  begin
    bump_info = repo.from_file
  rescue Errno::ENOENT
    log_red "Error: the file `#{@file}` not found."
    return nil
  end

  bump_info
end
log(message = '', newline = true) click to toggle source

Logs the message

@param [String] message @param [Boolean] newline @return [void]

# File lib/bump/application.rb, line 269
def log(message = '', newline = true)
  @logger.log message, newline
end
log_green(message, newline = true) click to toggle source

Logs the message in green

@param [String] message @param [Boolean] newline @return [void]

# File lib/bump/application.rb, line 287
def log_green(message, newline = true)
  log @logger.green(message), newline
end
log_red(message, newline = true) click to toggle source

Logs the message in red

@param [String] message @param [Boolean] newline @return [void]

# File lib/bump/application.rb, line 278
def log_red(message, newline = true)
  log @logger.red(message), newline
end
main() click to toggle source

The entry point

@return [void]

# File lib/bump/application.rb, line 251
def main
  case select_action
  when :version
    action_version
  when :help
    action_help
  when :info
    action_info
  when :bump
    action_bump
  end
end
print_bump_plan(bump_info) click to toggle source

Prints the version bump plan. @param [Bump::BumpInfo] bump_info The bump info

print_bump_plan_level(level, bump_info) click to toggle source

Prints the bump plan for the given level. @param [Symbol] level The level @param [Bump::BumpInfo] bump_info The bump info

print_bump_plan_preid(preid, bump_info) click to toggle source

Prints the bump plan for the give preid. @param [Bump::BumpInfo] bump_info The bump info

print_bump_plan_release(bump_info) click to toggle source

Prints the bump plan for the release @param [Bump::BumpInfo] bump_info The bump info

print_invalid_bump_info(bump_info) click to toggle source

Checks the bumping is possible. @param [Bump::BumpInfo] bumpInfo @return [void]

print_rule(rule) click to toggle source

Prints the pattern info for the given rule @param [Bump::FileUpdateRule] rule The rule

print_version_patterns(bump_info) click to toggle source

Shows the version patterns. @param [Bump::BumpInfo] bumpInfo @return [void]

print_version_transition(bump_info) click to toggle source

Prints the version transition. @param [Bump::BumpInfo] bump_info The bump info

report(bump_info) click to toggle source

Reports the bumping details. @param [Bump::BumpInfo] bumpInfo

# File lib/bump/application.rb, line 147
def report(bump_info)
  bump_info.update_rules.each do |rule|
    log rule.file.to_s
    log '  Performed pattern replacement:'
    log_green "    '#{rule.before_pattern}' => '#{rule.after_pattern}'"
    log
  end
end
save_bump_info(bump_info) click to toggle source

Saves the bump info @param [Bump::BumpInfo] bumpInfo @return [void]

# File lib/bump/application.rb, line 80
def save_bump_info(bump_info)
  repo = BumpInfoRepository.new @file

  repo.save bump_info
end
select_action() click to toggle source

Returns a symbol which represents the action to perform. @return [Symbol]

# File lib/bump/application.rb, line 24
def select_action
  return :help if @options[:help]

  return :version if @options[:version]

  return :info if @options[:info]

  return :bump if bump_option? @options

  # command without options invokes info action
  :info
end