Class: Mongrel::URIClassifier

Class | Mongrel::URIClassifier
In: | lib/mongrel/uri_classifier.rb lib/mongrel/uri_classifier.rb
Parent: | Object

### Methods

new new register register resolve resolve unregister unregister uris uris

### Classes and Modules

Class Mongrel::URIClassifier::RegistrationError
Class Mongrel::URIClassifier::UsageError

### Attributes

handler_map | [R] |
handler_map | [R] |

### Public Class methods

new()

[Source]

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

new()

[Source]

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

### Public Instance methods

register(uri, handler)

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.

[Source]

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

register(uri, handler)

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.

[Source]

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

resolve(request_uri)

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

[Source]

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

resolve(request_uri)

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

[Source]

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

unregister(uri)

Unregister a particular URI and its handler.

[Source]

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

unregister(uri)

Unregister a particular URI and its handler.

[Source]

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

uris()

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

[Source]

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

uris()

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

[Source]

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

[Validate]