Sha256: 12dac407ac7b6d4177c7c716a648221761ede340460460425bb1dca4ef9396c3

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

require 'rake'
require 'rake/tasklib'
require 'stove'

#
# @todo Most of these options are duplicated from the CLI, can we unify?
#
module Stove
  class RakeTask < Rake::TaskLib
    include Mixin::Loggable

    class << self
      #
      # Define a CLI option.
      #
      # @param [Symbol] option
      #
      def option(option)
        define_method("#{option}=".to_sym) do |value|
          log.debug("Setting #{option} = #{value.inspect}")
          options[option.to_sym] = value
        end
      end
    end

    # Actions
    Action.constants.map(&Action.method(:const_get)).select(&:id).each do |action|
      option action.id
    end

    # Plugins
    Plugin.constants.map(&Plugin.method(:const_get)).select(&:id).each do |plugin|
      option plugin.id
    end

    option :category
    option :path
    option :remote
    option :branch

    def initialize(name = nil)
      yield self if block_given?

      desc 'Publish this cookbook' unless ::Rake.application.last_comment
      task(name || :publish, :version) do |t, args|
        log.info("Options: #{options.inspect}")

        cookbook = Cookbook.new(options[:path])
        options[:version] = args[:version] || minor_bump(cookbook.version)
        Runner.run(cookbook, options)
      end
    end

    def locale=(locale)
      log.debug("Setting locale = #{locale.inspect}")
      I18n.locale = locale
    end

    def log_level=(level)
      log.debug("Setting log_level = #{level.inspect}")
      Stove.log_level = level
    end

    private

    def minor_bump(version)
      split = version.split('.').map(&:to_i)
      split[2] += 1
      split.join('.')
    end

    def options
      @options ||= Hash.new(true).tap do |h|
        h[:path] = Dir.pwd
        h[:jira] = false

        h[:remote]    = 'origin'
        h[:branch]    = 'master'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stove-2.0.0.beta.2 lib/stove/rake_task.rb
stove-2.0.0.beta.1 lib/stove/rake_task.rb