class RakeVersion::Tasks

Constants

NAMES
OTHER_NAMES

Public Class Methods

new(options = {}) { |config| ... } click to toggle source
# File lib/rake-version/tasks.rb, line 8
def initialize options = {}, &block
  @manager = RakeVersion::Manager.new
  @config = RakeVersion::Config.new
  yield @config if block_given?
  @manager.config = @config
  define options
end

Public Instance Methods

clear_tasks(options = {}) click to toggle source
# File lib/rake-version/tasks.rb, line 52
def clear_tasks options = {}
  task_names = NAMES
  task_names += OTHER_NAMES unless options[:clear_strict]
  task_names.each{ |task| remove_task task }
end
define(options = {}) click to toggle source
# File lib/rake-version/tasks.rb, line 16
def define options = {}

  clear_tasks options unless options[:clear] == false

  desc 'Show the current version'
  task :version do |t|
    handle_missing_version{ puts @manager.version.to_s }
  end

  namespace :version do

    desc 'Set the version (rake "version:set[1.2.3]")'
    task :set, :value do |t, args|
      puts @manager.set(args.value.to_s)
    end

    namespace :bump do

      [ :major, :minor, :patch ].each do |type|
        desc "Bump the #{type} version"
        task type do |t|
          handle_missing_version{ puts @manager.bump(type).to_s }
        end
      end
    end
  end
end
task(*args) { |t, args| ... } click to toggle source
Calls superclass method
# File lib/rake-version/tasks.rb, line 44
def task *args, &block
  super *args do |t, args|
    @manager.with_context context(t) do |m|
      yield t, args if block_given?
    end
  end
end

Private Instance Methods

context(task) click to toggle source
# File lib/rake-version/tasks.rb, line 74
def context task
  RakeVersion::Context.new task.application.original_dir
end
handle_missing_version() { || ... } click to toggle source
# File lib/rake-version/tasks.rb, line 60
def handle_missing_version
  return yield if Rake.application.options.trace
  begin
    yield
  rescue MissingVersionFile => e
    warn %|#{e.message}\nCreate it with:\n   rake "version:set[1.0.0]"|
    exit 1
  end
end
remove_task(task_name) click to toggle source
# File lib/rake-version/tasks.rb, line 70
def remove_task task_name
  Rake.application.remove_task task_name
end