Method: Consoler::Application#method_missing

Defined in:
lib/consoler/application.rb

#method_missing(command_name, input = nil) {|...| ... } ⇒ nil

Register a command for this app

Parameters:

  • command_name (Symbol)

    Name of the command

  • input (String, Consoler::Application) (defaults to: nil)

    Options definition or a complete subapp

Yields:

  • (...)

    Executed when the action is matched with parameters based on your options

Returns:

  • (nil)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/consoler/application.rb', line 57

def method_missing(command_name, input = nil, &block)
  action = nil
  options_def = ''

  unless block.nil?
    action = block
    options_def = input

    if !options_def.nil? && !options_def.instance_of?(String)
      raise 'Invalid options'
    end
  end

  if input.instance_of? Consoler::Application
    action = input
    options_def = ''
  end

  if action.nil?
    raise 'Invalid subapp/block'
  end

  command = command_name.to_s

  _add_command(command, options_def, action)

  nil
end