Sha256: 2bbf3b3761b2c8ae40d2b3118420c5b63e95d8e4979eca9e846b32760c5ccd9f

Contents?: true

Size: 1.86 KB

Versions: 4

Compression:

Stored size: 1.86 KB

Contents

require 'sinatra/base'
require 'deas/error_handler'

module Deas
  module SinatraApp

    def self.new(server_config)
      server_config.validate!

      Sinatra.new do

        # built-in settings
        set :environment, server_config.env
        set :root,        server_config.root

        set :public_folder, server_config.public_root
        set :views,         server_config.views_root

        set :dump_errors,      server_config.dump_errors
        set :method_override,  server_config.method_override
        set :sessions,         server_config.sessions
        set :static,           server_config.static_files
        set :reload_templates, server_config.reload_templates
        set :logging,          false

        # raise_errors and show_exceptions prevent Deas error handlers from
        # being called and Deas' logging doesn't finish. They should always be
        # false.
        set :raise_errors,     false
        set :show_exceptions,  false

        # custom settings
        set :deas_error_procs,     server_config.error_procs
        set :deas_default_charset, server_config.default_charset
        set :logger,               server_config.logger
        set :router,               server_config.router
        set :template_source,      server_config.template_source

        server_config.settings.each{ |set_args| set *set_args }
        server_config.middlewares.each{ |use_args| use *use_args }

        # routes
        server_config.routes.each do |route|
          send(route.method, route.path){ route.run(self) }
        end

        # error handling
        not_found do
          env['sinatra.error'] ||= Sinatra::NotFound.new
          ErrorHandler.run(env['sinatra.error'], self, settings.deas_error_procs)
        end
        error do
          ErrorHandler.run(env['sinatra.error'], self, settings.deas_error_procs)
        end

      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deas-0.33.0 lib/deas/sinatra_app.rb
deas-0.32.0 lib/deas/sinatra_app.rb
deas-0.31.0 lib/deas/sinatra_app.rb
deas-0.30.0 lib/deas/sinatra_app.rb