Sha256: d9b693faeb45602979abb4ed19a2f58f8fc725492adbab52d87c29f5fe9ec6b5

Contents?: true

Size: 1.94 KB

Versions: 2

Compression:

Stored size: 1.94 KB

Contents

# encoding: utf-8
module TestServer
  module App
    class ApplicationController < Sinatra::Base
      set :root, ::File.expand_path('../../', __FILE__)
      set :haml, :format => :html5

      enable :protect_from_csrf
      enable :protection
      enable :session
      enable :report_csrf_failure

      register Padrino::Helpers
      register Padrino::Routing

      use Rack::Deflater
      use Rack::Locale
      use Rack::NestedParams
      use Rack::PostBodyContentTypeParser

      helpers Sinatra::Param

      error do
        handler = ErrorHandler.find(StandardError)

        @error_summary = handler.summary(:html)
        @error_details = handler.details(:html)

        halt 500, haml(:error, layout: :application)
      end

      set :raise_sinatra_param_exceptions, true

      error Sinatra::Param::InvalidParameterError do
        handler = ErrorHandler.find(Sinatra::Param::InvalidParameterError)
        handler.use(JSON.dump(parameter: env['sinatra.error'].param))

        @error_summary = handler.summary(:html)
        @error_details = handler.details(:html)

        halt 401, haml(:error, layout: :application)
      end

      configure :profile do
        require 'ruby-prof'
        use Rack::RubyProf, files: '/tmp/profiles'

        use Rack::CommonLogger, TestServer::AccessLogger.new(TestServer.config.access_log)
        set :raise_errors, false
      end

      configure :production do
        use Rack::CommonLogger, TestServer::AccessLogger.new(TestServer.config.access_log)
        set :raise_errors, false
      end

      configure :development do
        set :raise_errors, true

        before do
          TestServer.ui_logger.debug "Parameters: " + params.to_s
        end
      end

      configure :test do
        use Rack::CommonLogger, TestServer::NullAccessLogger.new
        set :raise_errors, false
      end

      helpers do
        include Sprockets::Helpers
        include TestServer::WebHelper
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
test_server-0.2.4 app/controllers/application_controller.rb
test_server-0.2.3 app/controllers/application_controller.rb