Sha256: edc37ae205064e39f4650284ddac6f6843ea689c128bdced513efde35fd56edf

Contents?: true

Size: 1.81 KB

Versions: 13

Compression:

Stored size: 1.81 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_folder
        set :views,         server_config.views_folder

        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_template_scope,  server_config.template_scope
        set :deas_error_procs,     server_config.error_procs
        set :deas_default_charset, server_config.default_charset
        set :logger,               server_config.logger

        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

13 entries across 13 versions & 1 rubygems

Version Path
deas-0.23.0 lib/deas/sinatra_app.rb
deas-0.22.1 lib/deas/sinatra_app.rb
deas-0.22.0 lib/deas/sinatra_app.rb
deas-0.21.0 lib/deas/sinatra_app.rb
deas-0.20.0 lib/deas/sinatra_app.rb
deas-0.19.0 lib/deas/sinatra_app.rb
deas-0.18.0 lib/deas/sinatra_app.rb
deas-0.17.1 lib/deas/sinatra_app.rb
deas-0.17.0 lib/deas/sinatra_app.rb
deas-0.16.0 lib/deas/sinatra_app.rb
deas-0.15.0 lib/deas/sinatra_app.rb
deas-0.14.1 lib/deas/sinatra_app.rb
deas-0.14.0 lib/deas/sinatra_app.rb