Class: Carrasco::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/carrasco/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_name, options = {}) ⇒ Command

Returns a new instance of Command.



8
9
10
11
12
13
14
# File 'lib/carrasco/command.rb', line 8

def initialize(command_name, options = {})
  options = Thor::CoreExt::HashWithIndifferentAccess.new(options)
  @command_name = command_name
  @command      = options[:command] || command_name
  @help         = options[:help] || command_name
  @description  = options[:description] || "description not given"
end

Instance Attribute Details

#commandObject (readonly) Also known as: to_s

Returns the value of attribute command.



5
6
7
# File 'lib/carrasco/command.rb', line 5

def command
  @command
end

#command_nameObject (readonly)

Returns the value of attribute command_name.



5
6
7
# File 'lib/carrasco/command.rb', line 5

def command_name
  @command_name
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/carrasco/command.rb', line 5

def description
  @description
end

#helpObject (readonly)

Returns the value of attribute help.



5
6
7
# File 'lib/carrasco/command.rb', line 5

def help
  @help
end

Instance Method Details

#inject_into_class(klass) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/carrasco/command.rb', line 16

def inject_into_class(klass)
  command = self
  klass.desc(help, description)
  klass.class_eval do
    define_method(command.command_name) do
      execute_command(command)
    end
  end
end