Class: Lennarb::Application

Inherits:
App
  • Object
show all
Defined in:
lib/lennarb/application.rb,
lib/lennarb/application/request_handler.rb

Overview

The Standar version to build web applications.

Defined Under Namespace

Classes: RequestHandler

Constant Summary

Constants inherited from App

Lennarb::App::AlreadyInitializedError

Instance Attribute Summary

Attributes inherited from App

#env, #root

Instance Method Summary collapse

Methods inherited from App

#config, #controllers, #freeze!, #initialize, #initialized?, #mount, #routes

Constructor Details

This class inherits a constructor from Lennarb::App

Instance Method Details

#appObject

The Rack app.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lennarb/application.rb', line 25

def app
  @app ||= begin
    stack = middleware.to_a

    request_handler = Application::RequestHandler.new(self)

    Rack::Builder.app do
      stack.each { |middleware, args, block| use(middleware, *args, &block) }
      run request_handler
    end
  end
end

#call(env) ⇒ Object

Call the app.

@param env



42
43
44
45
# File 'lib/lennarb/application.rb', line 42

def call(env)
  env[RACK_LENNA_BASE] = self
  Dir.chdir(root) { return app.call(env) }
end

#default_middleware_stackObject

The default middleware stack. It includes the following middlewares:

  • Rack::CommonLogger

  • Rack::Runtime

  • Rack::Head

  • Rack::Etag

  • Lennarb::Middleware::LennaHeader

  • Rack::ShowExceptions (only in development)

@return



68
69
70
71
72
73
74
75
76
# File 'lib/lennarb/application.rb', line 68

def default_middleware_stack
  MiddlewareStack.new.tap do |middleware|
    middleware.use(Rack::CommonLogger)
    middleware.use(Rack::Runtime)
    middleware.use(Rack::Head)
    middleware.use(Rack::ETag)
    middleware.use Rack::ShowExceptions if env.development?
  end
end

#initialize!Object

See Also:

  • Lennarb::Application.{Lennarb{Lennarb::App{Lennarb::App#initialize}


6
7
8
9
# File 'lib/lennarb/application.rb', line 6

def initialize!
  super
  freeze!
end

#middlewareObject

The middleware stack.

@return



15
16
17
18
19
# File 'lib/lennarb/application.rb', line 15

def middleware
  @middleware = default_middleware_stack
  @middleware.instance_eval(&block) if block_given?
  @middleware
end