Sha256: 9a69574f270834dc00c302ebdf96652569c3e62fccec119e90a8726a684fee77

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require 'active_support'
require 'active_support/core_ext/string/inflections'

require_relative 'commands/check'
require_relative 'commands/clean'
require_relative 'commands/deps'
require_relative 'commands/run'
require_relative 'commands/uberjar'
require_relative 'commands/version'

module RubyLeiningen
  module Commands
    class << self
      def define_custom_command(name, options = {}, &config_block)
        klass_name = name.classify
        config = (config_block || lambda { |conf| conf }).call(Config.new)

        klass = Class.new(Base) do
          unless options[:include_profile_support] == false
            include Mixins::Profile
          end

          define_method "configure_command" do |builder, opts|
            builder = super(builder, opts)
            builder = builder.with_subcommand(name) do |sub|
              config.subcommand_block.call(sub, opts)
            end
            config.command_block.call(builder, opts)
          end
        end

        const_set(klass_name, klass)
      end
    end

    private

    class Config
      attr_accessor :command_block, :subcommand_block

      def initialize
        self.command_block = lambda { |com, _| com }
        self.subcommand_block = lambda { |sub, _| sub }
      end

      def on_command_builder(&block)
        self.command_block = block
        self
      end

      def on_subcommand_builder(&block)
        self.subcommand_block = block
        self
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby_leiningen-0.0.2 lib/ruby_leiningen/commands.rb
ruby_leiningen-0.0.1 lib/ruby_leiningen/commands.rb