Sha256: 07c382838c7e1f55dc567407d79ae30664ca9a190d0379643ca0a98a0bd7d58a

Contents?: true

Size: 1017 Bytes

Versions: 1

Compression:

Stored size: 1017 Bytes

Contents

module Pakyow
  module Middleware
    class NotFound
      def initialize(app)
        @app = app
      end

      def call(env)
        @app.call(env)
        
        # 404 if no route matched and no views were found
        unless found?
          Log.enter "[404] Not Found"

          Pakyow.app.response.body = [] 
          Pakyow.app.presenter.reset if Pakyow.app.presenter

          Pakyow.app.response.status = 404
          Pakyow.app.router.handle!(404)

          if Pakyow.app.presenter
            # consider moving to presenter middleware
            # Pakyow.app.presenter.prepare_for_request(Pakyow.app.request)
            Pakyow.app.response.body = [Pakyow.app.presenter.content] if Pakyow.app.presenter.presented?
          end
        end
      end

      private

      def found?
        return true if Pakyow.app.router.routed?
        return true if Pakyow.app.presenter && Pakyow.app.presenter.presented? && Configuration::App.all_views_visible

        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pakyow-core-0.8rc1 pakyow-core/lib/core/middleware/not_found.rb