Class: Orange::Middleware::FlexRouter

Inherits:
Base
  • Object
show all
Defined in:
lib/orange-more/sitemap/middleware/flex_router.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#packet_call(packet) ⇒ Object

Sets the sitemap resource as the router if the resource can accept the path.



16
17
18
19
20
21
22
# File 'lib/orange-more/sitemap/middleware/flex_router.rb', line 16

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