Class: DLDInternet::Thor::DynamicCommand

Inherits:
Thor::DynamicCommand
  • Object
show all
Defined in:
lib/dldinternet/thor/dynamic_command.rb

Instance Method Summary collapse

Instance Method Details

#run(instance, args = []) ⇒ Object

By default, a command invokes a method in the thor class. You can change this implementation to create custom commands.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dldinternet/thor/dynamic_command.rb', line 9

def run(instance, args = [])
  arity = nil

  if private_method?(instance)
    instance.class.handle_no_command_error(name)
  elsif public_method?(instance)
    arity = instance.method(name).arity
    instance.__send__(name, *args)
  elsif local_method?(instance, :method_missing)
    instance.__send__(:method_missing, name.to_sym, *args)
  else
    if instance.class.instance_methods.include?(:handle_no_command_error)
      instance.handle_no_command_error(name)
    else
      instance.class.handle_no_command_error(name)
    end
  end
rescue ArgumentError => e
  handle_argument_error?(instance, e, caller) ? instance.class.handle_argument_error(self, e, args, arity) : (raise e)
rescue ::Thor::NoMethodError => e
  handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_command_error(name) : (raise e)
end