class Deas::Server::Config

Constants

DEFAULT_ENV

Attributes

after_route_run_procs[RW]
before_route_run_procs[RW]
env[RW]
error_procs[RW]
init_procs[RW]
logger[RW]
method_override[RW]
middlewares[RW]
root[RW]
router[RW]
show_exceptions[RW]
template_source[RW]
verbose_logging[RW]

Public Class Methods

new() click to toggle source
# File lib/deas/server.rb, line 144
def initialize
  @env                    = DEFAULT_ENV
  @root                   = ENV['PWD']
  @method_override        = true
  @show_exceptions        = false
  @verbose_logging        = true
  @middlewares            = []
  @init_procs             = []
  @error_procs            = []
  @before_route_run_procs = []
  @after_route_run_procs  = []
  @template_source        = nil
  @logger                 = Deas::NullLogger.new
  @router                 = Deas::Router.new

  @valid = nil
end

Public Instance Methods

routes() click to toggle source
# File lib/deas/server.rb, line 170
def routes
  self.router.routes
end
urls() click to toggle source
# File lib/deas/server.rb, line 166
def urls
  self.router.urls
end
valid?() click to toggle source
# File lib/deas/server.rb, line 174
def valid?
  !!@valid
end
validate!() click to toggle source

for the config to be considered “valid”, a few things need to happen. The key here is that this only needs to be done once for each config.

# File lib/deas/server.rb, line 181
def validate!
  return @valid if !@valid.nil?  # only need to run this once per config

  # ensure all user and plugin configs are applied
  self.init_procs.each(&:call)
  raise Deas::ServerRootError if self.root.nil?

  # validate the router
  self.router.validate!

  # TODO: build final middleware stack when building the rack app, not here
  # (once Sinatra is removed)

  # prepend the method override middleware first.  This ensures that the
  # it is run before any other middleware
  self.middlewares.unshift([Rack::MethodOverride]) if self.method_override

  # append the show exceptions and logging middlewares next-to-last. This
  # ensures the logging and exception showing happens just before the
  # optional trailing slashes handling.  It should be just before the app
  # gets the request and just after the app sends a response (except for
  # trailing slashes - this should happen inside of the show exceptions
  # and logging behavior).
  self.middlewares << [Deas::ShowExceptions] if self.show_exceptions
  self.middlewares << [
    Deas::Logging.middleware_type(self.verbose_logging),
    self.logger
  ]

  # optionally add the trailing slashes middleware last b/c it should
  # happen inside of show exceptions and logging.  we want the behavior
  # to feel like app behavior to the rest of the middleware stack so it
  # needs to be just before the app gest the request and just after the
  # app sends a response.
  if self.router.trailing_slashes_set?
    self.middlewares << [Deas::TrailingSlashes, self.router]
  end

  self.middlewares.freeze

  @valid = true # if it made it this far, its valid!
end