Sha256: d2f7fc81e014fbe56d8c3dbed70bf2c622f64250d45b11642f0c5b64ca0c3fcf

Contents?: true

Size: 868 Bytes

Versions: 12

Compression:

Stored size: 868 Bytes

Contents

# frozen_string_literal: true

module Pakyow
  module Actions
    class Dispatch
      def call(connection)
        catch :halt do
          Pakyow.apps.each do |app|
            if connection.path.start_with?(app.mount_path)
              app.call(connection)
            end
          end
        end

        unless connection.halted?
          error_404(connection)
        end
      rescue StandardError => error
        connection.error = error
        connection.logger.houston(error)
        error_500(connection)
      end

      private

      def error_404(connection, message = "404 Not Found")
        connection.status = 404
        connection.body = StringIO.new(message)
      end

      def error_500(connection, message = "500 Server Error")
        connection.status = 500
        connection.body = StringIO.new(message)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pakyow-core-1.0.6 lib/pakyow/actions/dispatch.rb
pakyow-core-1.0.5 lib/pakyow/actions/dispatch.rb
pakyow-core-1.0.4 lib/pakyow/actions/dispatch.rb
pakyow-core-1.0.3 lib/pakyow/actions/dispatch.rb
pakyow-core-1.0.2 lib/pakyow/actions/dispatch.rb
pakyow-core-1.0.1 lib/pakyow/actions/dispatch.rb
pakyow-core-1.0.0 lib/pakyow/actions/dispatch.rb
pakyow-core-1.0.0.rc5 lib/pakyow/environment/actions/dispatch.rb
pakyow-core-1.0.0.rc4 lib/pakyow/environment/actions/dispatch.rb
pakyow-core-1.0.0.rc3 lib/pakyow/environment/actions/dispatch.rb
pakyow-core-1.0.0.rc2 lib/pakyow/environment/actions/dispatch.rb
pakyow-core-1.0.0.rc1 lib/pakyow/environment/actions/dispatch.rb