Class: Thor::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/minfra/cli/hook.rb

Instance Method Summary collapse

Instance Method Details

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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/minfra/cli/hook.rb', line 7

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

  if private_method?(instance)
    instance.class.handle_no_command_error(name)
  elsif public_method?(instance)
    hooks = instance.instance_variable_get(:@_invocations).values.flatten
    arity = instance.method(name).arity
    Minfra::Cli.call_before_hooks(instance, ['all']) if hooks.size == 1
    Minfra::Cli.call_before_hooks(instance, hooks)
#        debugger
    instance.__send__(name, *args)
    Minfra::Cli.call_after_hooks(instance, hooks)
    Minfra::Cli.call_after_hooks(instance, ['all']) if hooks.size == 1
  elsif local_method?(instance, :method_missing)
    # Minfra::Cli.call_before_hooks(instance,hooks)
    instance.__send__(:method_missing, name.to_sym, *args)
    # Minfra::Cli.call_after_hooks(instance,hooks)
  else
    instance.class.handle_no_command_error(name)
  end
rescue ArgumentError => e
  if handle_argument_error?(instance, e,
                            caller)
    instance.class.handle_argument_error(self, e, args, arity)
  else
    (raise e)
  end
rescue NoMethodError => e
  handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_command_error(name) : (raise e)
end