Class: Mongrel::URIClassifier

### Home Classes Methods

### In Files

- lib/mongrel/uri_classifier.rb

### Parent

Object

### Namespace

- CLASS Mongrel::URIClassifier::RegistrationError
- CLASS Mongrel::URIClassifier::UsageError

### Methods

- ::new
- #register
- #resolve
- #unregister
- #uris

### Files

- CHANGELOG
- COPYING
- LICENSE
- README
- Makefile

### Class/Module Index

Quicksearch

- Mongrel
- Mongrel::CGIWrapper
- Mongrel::Camping
- Mongrel::Camping::CampingHandler
- Mongrel::Command
- Mongrel::Command::Base
- Mongrel::Command::Registry
- Mongrel::Configurator
- Mongrel::Const
- Mongrel::DeflateFilter
- Mongrel::DirHandler
- Mongrel::Error404Handler
- Mongrel::Gems
- Mongrel::HeaderOut
- Mongrel::HttpHandler
- Mongrel::HttpHandlerPlugin
- Mongrel::HttpParams
- Mongrel::HttpParser
- Mongrel::HttpParserError
- Mongrel::HttpRequest
- Mongrel::HttpResponse
- Mongrel::HttpServer
- Mongrel::Rails
- Mongrel::Rails::RailsConfigurator
- Mongrel::Rails::RailsHandler
- Mongrel::RedirectHandler
- Mongrel::StatisticsFilter
- Mongrel::Stats
- Mongrel::StatusHandler
- Mongrel::StopServer
- Mongrel::TimeoutError
- Mongrel::URIClassifier
- Mongrel::URIClassifier::RegistrationError
- Mongrel::URIClassifier::UsageError
- RequestLog
- RequestLog::Access
- RequestLog::Files
- RequestLog::Objects
- RequestLog::Params
- RequestLog::Threads
- IO
- Kernel
- MongrelDbg
- TCPServer

No matching classes.

# Mongrel::URIClassifier

### Attributes

handler_map[R]

### Public Class Methods

new() click to toggle source

    # File lib/mongrel/uri_classifier.rb, line 17
    def initialize
      @handler_map = {}
      @matcher = //
      @root_handler = nil
    end

### Public Instance Methods

register(uri, handler) click to toggle source

Register a handler object at a particular URI. The handler can be whatever you want, including an array. It's up to you what to do with it.

Registering a handler is not necessarily threadsafe, so be careful if you go mucking around once the server is running.

    # File lib/mongrel/uri_classifier.rb, line 28
    def register(uri, handler)
      raise RegistrationError, "#{uri.inspect} is already registered" if @handler_map[uri]
      raise RegistrationError, "URI is empty" if !uri or uri.empty?
      raise RegistrationError, "URI must begin with a \"#{Const::SLASH}\"" unless uri[0..0] == Const::SLASH
      @handler_map[uri.dup] = handler
      rebuild
    end

resolve(request_uri) click to toggle source

Resolve a request URI by finding the best partial match in the registered handler URIs.

    # File lib/mongrel/uri_classifier.rb, line 46
    def resolve(request_uri)
      if @root_handler
        # Optimization for the pathological case of only one handler on "/"; e.g. Rails
        [Const::SLASH, request_uri, @root_handler]
      elsif match = @matcher.match(request_uri)
        uri = match.to_s
        # A root mounted ("/") handler must resolve such that path info matches the original URI.
        [uri, (uri == Const::SLASH ? request_uri : match.post_match), @handler_map[uri]]
      else
        [nil, nil, nil]
      end
    end

unregister(uri) click to toggle source

Unregister a particular URI and its handler.

    # File lib/mongrel/uri_classifier.rb, line 37
    def unregister(uri)
      handler = @handler_map.delete(uri)
      raise RegistrationError, "#{uri.inspect} was not registered" unless handler
      rebuild
      handler
    end

uris() click to toggle source

Returns the URIs that have been registered with this classifier so far.

    # File lib/mongrel/uri_classifier.rb, line 13
    def uris
      @handler_map.keys
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.