Sha256: f754a80f175bcd84efb06618398e94675418ea03e7164a60ddd1d8e1ffa4ef78

Contents?: true

Size: 1.52 KB

Versions: 101

Compression:

Stored size: 1.52 KB

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The not_found plugin adds a +not_found+ class method which sets
    # a block that is called whenever a 404 response with an empty body
    # would be returned.  The usual use case for this is the desire for
    # nice error pages if the page is not found.
    #
    # You can provide the block with the plugin call:
    #
    #   plugin :not_found do
    #     "Where did it go?"
    #   end
    #   
    # Or later via a separate call to +not_found+:
    #
    #   plugin :not_found
    #
    #   not_found do
    #     "Where did it go?"
    #   end
    #
    # Before not_found is called, any existing headers on the response
    # will be cleared.  So if you want to be sure the headers are set
    # even in a not_found block, you need to reset them in the
    # not_found block.
    #
    # This plugin is now a wrapper around the +status_handler+ plugin and
    # still exists mainly for backward compatibility.
    module NotFound
      # Require the status_handler plugin
      def self.load_dependencies(app)
        app.plugin :status_handler
      end

      # If a block is given, install the block as the not_found handler.
      def self.configure(app, &block)
        if block
          app.not_found(&block)
        end
      end

      module ClassMethods
        # Install the given block as the not_found handler.
        def not_found(&block)
          status_handler(404, &block)
        end
      end
    end

    register_plugin(:not_found, NotFound)
  end
end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
roda-3.79.0 lib/roda/plugins/not_found.rb
roda-3.78.0 lib/roda/plugins/not_found.rb
roda-3.77.0 lib/roda/plugins/not_found.rb
roda-3.76.0 lib/roda/plugins/not_found.rb
roda-3.75.0 lib/roda/plugins/not_found.rb
roda-3.74.0 lib/roda/plugins/not_found.rb
roda-3.73.0 lib/roda/plugins/not_found.rb
roda-3.72.0 lib/roda/plugins/not_found.rb
roda-3.71.0 lib/roda/plugins/not_found.rb
roda-3.70.0 lib/roda/plugins/not_found.rb
roda-3.69.0 lib/roda/plugins/not_found.rb
roda-3.68.0 lib/roda/plugins/not_found.rb
roda-3.67.0 lib/roda/plugins/not_found.rb
roda-3.66.0 lib/roda/plugins/not_found.rb
roda-3.65.0 lib/roda/plugins/not_found.rb
roda-3.64.0 lib/roda/plugins/not_found.rb
roda-3.63.0 lib/roda/plugins/not_found.rb
roda-3.62.0 lib/roda/plugins/not_found.rb
roda-3.61.0 lib/roda/plugins/not_found.rb
roda-3.60.0 lib/roda/plugins/not_found.rb