Sha256: fe8f0aa5f75b93ee9e39f4aa936daff2353f8f0922a5f192539f0435ab46ae5e

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require "thor/core_ext/hash_with_indifferent_access"

module Carrasco
  class Group
    InvalidGroupError = Class.new(StandardError)

    attr_reader :command_name, :commands, :description, :help, :break_on_failure

    def initialize(group_name, options = {})
      options = Thor::CoreExt::HashWithIndifferentAccess.new(options)
      @command_name     = group_name
      @help             = options[:help] || command_name
      @description      = options[:description] || "description not given"
      @break_on_failure = options[:break_on_failure]
      @break_on_failure = true if break_on_failure.nil?
      @commands         = options.fetch('commands') do
        raise InvalidGroupError, "Commands not provided for group '#{group_name}'"
      end
    end

    def inject_into_class(klass)
      group = self
      klass.desc(help, description)
      klass.class_eval do
        define_method(group.command_name) do
          execute_commands(group.commands, group.break_on_failure)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carrasco-0.1.6 lib/carrasco/group.rb