Class: Ppl::Application::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/ppl/application/router.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_suite) ⇒ Router

Returns a new instance of Router.



7
8
9
10
# File 'lib/ppl/application/router.rb', line 7

def initialize(command_suite)
  @command_suite = command_suite
  @aliases = {}
end

Instance Attribute Details

#aliasesObject

Returns the value of attribute aliases.



3
4
5
# File 'lib/ppl/application/router.rb', line 3

def aliases
  @aliases
end

#defaultObject

Returns the value of attribute default.



4
5
6
# File 'lib/ppl/application/router.rb', line 4

def default
  @default
end

#external_commandObject

Returns the value of attribute external_command.



5
6
7
# File 'lib/ppl/application/router.rb', line 5

def external_command
  @external_command
end

Instance Method Details

#route(argument) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ppl/application/router.rb', line 12

def route(argument)
  command = @command_suite.find_command(argument)
  if command.nil? && @aliases.has_key?(argument)
    if is_bang_alias?(argument)
      command = create_external_command(argument)
    else
      command = @command_suite.find_command(@aliases[argument])
    end
  end
  if command.nil? && !@default.nil?
    command = @command_suite.find_command(@default)
  end
  return command
end