Command   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %
Metric Value
wmc 2
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 7 1
A inject_into_class() 0 9 1
1
require "thor/core_ext/hash_with_indifferent_access"
2
3
module Carrasco
4
  class Command
5
    attr_reader :command_name, :command, :description, :help
6
    alias_method :to_s, :command
7
8
    def initialize(command_name, options = {})
9
      options = Thor::CoreExt::HashWithIndifferentAccess.new(options)
10
      @command_name = command_name
11
      @command      = options[:command] || command_name
12
      @help         = options[:help] || command_name
13
      @description  = options[:description] || "description not given"
14
    end
15
16
    def inject_into_class(klass)
17
      command = self
18
      klass.desc(help, description)
19
      klass.class_eval do
20
        define_method(command.command_name) do
21
          execute_command(command)
22
        end
23
      end
24
    end
25
  end
26
end
27