Class: Lotus::Middleware Private
- Inherits:
-
Object
- Object
- Lotus::Middleware
- Defined in:
- lib/lotus/middleware.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Rack middleware stack for an application
Instance Method Summary collapse
-
#_load_assets_middleware ⇒ Object
private
Use static assets middleware.
-
#_load_default_welcome_page_for(application) ⇒ Object
private
Default welcome page.
-
#_load_session_middleware ⇒ Object
private
Add session middleware.
-
#call(env) ⇒ Array
private
Process a request.
-
#initialize(configuration) ⇒ Lotus::Middleware
constructor
private
Instantiate a middleware stack.
-
#load!(application, namespace) ⇒ Lotus::Middleware
private
Load the middleware stack.
- #load_default_stack(application) ⇒ Object private
- #load_middleware(middleware) ⇒ Object private
-
#prepend(middleware, *args, &blk) ⇒ Array
private
Prepend a middleware to the stack.
-
#use(middleware, *args, &blk) ⇒ Array
private
Append a middleware to the stack.
Constructor Details
#initialize(configuration) ⇒ Lotus::Middleware
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instantiate a middleware stack
17 18 19 20 |
# File 'lib/lotus/middleware.rb', line 17 def initialize(configuration) @stack = [] @configuration = configuration end |
Instance Method Details
#_load_assets_middleware ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use static assets middleware
134 135 136 137 138 139 140 141 |
# File 'lib/lotus/middleware.rb', line 134 def _load_assets_middleware env = Lotus.environment if !env.container? && env.serve_static_assets? require 'lotus/static' use Lotus::Static end end |
#_load_default_welcome_page_for(application) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Default welcome page
113 114 115 116 117 118 |
# File 'lib/lotus/middleware.rb', line 113 def _load_default_welcome_page_for(application) unless Lotus.env?(:test) || application.routes.defined? require 'lotus/welcome' use Lotus::Welcome end end |
#_load_session_middleware ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add session middleware
124 125 126 127 128 |
# File 'lib/lotus/middleware.rb', line 124 def _load_session_middleware if @configuration.sessions.enabled? prepend(*@configuration.sessions.middleware) end end |
#call(env) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Process a request. This method makes the middleware stack compatible with the Rack protocol.
51 52 53 |
# File 'lib/lotus/middleware.rb', line 51 def call(env) @builder.call(env) end |
#load!(application, namespace) ⇒ Lotus::Middleware
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load the middleware stack
32 33 34 35 36 37 38 39 40 |
# File 'lib/lotus/middleware.rb', line 32 def load!(application, namespace) @namespace = namespace @builder = ::Rack::Builder.new load_default_stack(application) @stack.each { |m, args, block| @builder.use load_middleware(m), *args, &block } @builder.run application.routes self end |
#load_default_stack(application) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/lotus/middleware.rb', line 98 def load_default_stack(application) @default_stack_loaded ||= begin _load_assets_middleware _load_session_middleware _load_default_welcome_page_for(application) use Rack::MethodOverride true end end |
#load_middleware(middleware) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 90 91 92 93 94 |
# File 'lib/lotus/middleware.rb', line 87 def load_middleware(middleware) case middleware when String @namespace.const_get(middleware) else middleware end end |
#prepend(middleware, *args, &blk) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prepend a middleware to the stack.
81 82 83 |
# File 'lib/lotus/middleware.rb', line 81 def prepend(middleware, *args, &blk) @stack.unshift [middleware, args, blk] end |
#use(middleware, *args, &blk) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Append a middleware to the stack.
66 67 68 |
# File 'lib/lotus/middleware.rb', line 66 def use(middleware, *args, &blk) @stack.push [middleware, args, blk] end |