Class: Orange::Middleware::FourOhFour

Inherits:
Base show all
Defined in:
lib/orange-core/middleware/four_oh_four.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

Methods inherited from Base

#call, #initialize, #inspect, #orange, #pass, #recapture

Constructor Details

This class inherits a constructor from Orange::Middleware::Base

Instance Method Details

#init(opts = {}) ⇒ Object



14
15
16
17
18
# File 'lib/orange-core/middleware/four_oh_four.rb', line 14

def init(opts = {})
  @resource = opts[:resource] || Orange::NotFound
  orange.load @resource.new, :not_found
  orange.add_pulp Orange::Pulp::NotFoundHelper
end

#packet_call(packet) ⇒ Object

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



22
23
24
25
26
27
28
29
30
# File 'lib/orange-core/middleware/four_oh_four.rb', line 22

def packet_call(packet)
  packet['route.router'] = orange[:not_found] unless packet['route.router']
  begin
    pass packet
  rescue Orange::NotFoundException
    orange[:not_found].route(packet)
    packet.finish
  end
end