Sha256: b59ac1eb12e6d0c950c869c5f02cc994c2bf9194be7965f96be969d2287cb6b8

Contents?: true

Size: 871 Bytes

Versions: 5

Compression:

Stored size: 871 Bytes

Contents

class Ppl::Application::Router

  attr_accessor :aliases
  attr_accessor :default
  attr_accessor :external_command

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

  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


  private

  def is_bang_alias?(key)
    @aliases[key].match(/^!/)
  end

  def create_external_command(key)
    @external_command.name = key
    @external_command.command = @aliases[key][1..-1]
    @external_command
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ppl-4.0.5 lib/ppl/application/router.rb
ppl-4.0.3 lib/ppl/application/router.rb
ppl-4.0.2 lib/ppl/application/router.rb
ppl-4.0.1 lib/ppl/application/router.rb
ppl-4.0.0 lib/ppl/application/router.rb