Sha256: 6dd61693bd035b7ac52ab577e5364cf856792c2ff61f5ad6c5583e65786e98d2

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

require 'orange/middleware/base'

module Orange::Middleware
  # The FlexRouter middleware takes a resource that can route paths and
  # then intercepts routes for that resource. By default,
  # it uses the Orange::SitemapResource. 
  # 
  # The resource is automatically loaded into the core as 
  # :sitemap. The resource must respond to "route?(path)" 
  # and "route(packet)".  
  # 
  # Pass a different routing resource using the :resource arg
  class FlexRouter < Base
    def init(opts = {})
      @resource = opts[:resource] || Orange::SitemapResource
      orange.load @resource.new, :sitemap
    end
    
    # Sets the sitemap resource as the router if the resource can accept 
    # the path.
    def packet_call(packet)
      return (pass packet) if packet['route.router']  # Don't route if other middleware
                                                      # already has
      path = packet['route.path'] || packet.request.path_info
      packet['route.router'] = orange[:sitemap] if orange[:sitemap].route?(packet, path)
      pass packet
    end
    
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
orange-0.0.13 lib/orange/middleware/flex_router.rb
orange-0.0.12 lib/orange/middleware/flex_router.rb
orange-0.0.10 lib/orange/middleware/flex_router.rb
orange-0.0.8 lib/orange/middleware/flex_router.rb
orange-0.0.7 lib/orange/middleware/flex_router.rb
orange-0.0.6 lib/orange/middleware/flex_router.rb
orange-0.0.5 lib/orange/middleware/flex_router.rb