Sha256: 860305d0fca1f4db7941d1ae20a92cdada05531de04556448893229995eaf0b9

Contents?: true

Size: 1.18 KB

Versions: 33

Compression:

Stored size: 1.18 KB

Contents

require 'orange-core/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 FourOhFour < Base
    def init(opts = {})
      @resource = opts[:resource] || Orange::NotFound
      orange.load @resource.new, :not_found
      orange.add_pulp Orange::Pulp::NotFoundHelper
    end
    
    # Sets the sitemap resource as the router if the resource can accept 
    # the path.
    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
    
  end
end

module Orange
  class NotFoundException < Exception
    
  end
  
  module Pulp::NotFoundHelper
    def not_found
      raise Orange::NotFoundException.new
    end
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
orange-core-0.7.1 lib/orange-core/middleware/four_oh_four.rb
orange-core-0.7.0 lib/orange-core/middleware/four_oh_four.rb
orange-core-0.6.0 lib/orange-core/middleware/four_oh_four.rb
orange-core-0.5.9 lib/orange-core/middleware/four_oh_four.rb
orange-core-0.5.8 lib/orange-core/middleware/four_oh_four.rb
orange-core-0.5.5 lib/orange-core/middleware/four_oh_four.rb
orange-core-0.5.3 lib/orange-core/middleware/four_oh_four.rb
orange-0.5.5 lib/orange-core/middleware/four_oh_four.rb
orange-0.5.4 lib/orange-core/middleware/four_oh_four.rb
orange-0.5.3 lib/orange-core/middleware/four_oh_four.rb
orange-0.5.2 lib/orange-core/middleware/four_oh_four.rb
orange-0.5.1 lib/orange-core/middleware/four_oh_four.rb
orange-0.4.0 lib/orange-core/middleware/four_oh_four.rb
orange-0.3.9 lib/orange-core/middleware/four_oh_four.rb
orange-0.3.8 lib/orange-core/middleware/four_oh_four.rb
orange-0.3.7 lib/orange-core/middleware/four_oh_four.rb
orange-0.3.6 lib/orange-core/middleware/four_oh_four.rb
orange-0.3.5 lib/orange-core/middleware/four_oh_four.rb
orange-0.3.4 lib/orange-core/middleware/four_oh_four.rb
orange-0.3.3 lib/orange-core/middleware/four_oh_four.rb