Class: Lotus::Application
- Inherits:
-
Object
- Object
- Lotus::Application
- Defined in:
- lib/lotus/application.rb
Overview
A full stack Lotus application
Instance Attribute Summary collapse
-
#renderer ⇒ Object
private
Rendering policy.
-
#routes ⇒ Lotus::Router
Return the routes for this application.
Class Method Summary collapse
-
.applications ⇒ Set
private
Registry of Lotus applications in the current Ruby process.
-
.configure(environment = nil, &blk) ⇒ Object
Configure the application.
-
.inherited(base) ⇒ Object
private
Override Ruby’s Class#inherited.
-
.load!(application = self) ⇒ Object
Eager load the application configuration, by activating the framework duplication mechanisms.
-
.preload! ⇒ Object
Preload all the registered applications, by yielding their configurations and preparing the frameworks.
-
.preload_applications! ⇒ Object
private
Full preload for all the registered applications.
Instance Method Summary collapse
-
#call(env) ⇒ Array
Process a request.
-
#configuration ⇒ Object
private
Return the configuration for this application.
-
#initialize(options = {}) ⇒ Lotus::Application
constructor
Initialize and load a new instance of the application.
-
#middleware ⇒ Lotus::Middleware
private
Rack middleware stack.
-
#name ⇒ Object
private
Return the application name.
Constructor Details
#initialize(options = {}) ⇒ Lotus::Application
Initialize and load a new instance of the application
109 110 111 112 |
# File 'lib/lotus/application.rb', line 109 def initialize( = {}) self.class.configuration.path_prefix [:path_prefix] self.class.load!(self) end |
Instance Attribute Details
#renderer ⇒ 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.
Rendering policy
@param [Lotus::RenderingPolicy]
102 103 104 |
# File 'lib/lotus/application.rb', line 102 def renderer @renderer end |
#routes ⇒ Lotus::Router
Return the routes for this application
86 87 88 |
# File 'lib/lotus/application.rb', line 86 def routes @routes end |
Class Method Details
.applications ⇒ Set
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.
Registry of Lotus applications in the current Ruby process
49 50 51 52 53 |
# File 'lib/lotus/application.rb', line 49 def self.applications synchronize do @@applications ||= Set.new end end |
.configure(environment = nil, &blk) ⇒ Object
Configure the application. It yields the given block in the context of the configuration
75 76 77 |
# File 'lib/lotus/application.rb', line 75 def self.configure(environment = nil, &blk) configuration.configure(environment, &blk) end |
.inherited(base) ⇒ 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.
Override Ruby’s Class#inherited
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lotus/application.rb', line 28 def self.inherited(base) super base.class_eval do include Lotus::Utils::ClassAttribute class_attribute :configuration self.configuration = Configuration.new end synchronize do applications.add(base) end end |
.load!(application = self) ⇒ Object
Eager load the application configuration, by activating the framework duplication mechanisms.
146 147 148 |
# File 'lib/lotus/application.rb', line 146 def self.load!(application = self) Lotus::Loader.new(application).load! end |
.preload! ⇒ Object
Preload all the registered applications, by yielding their configurations and preparing the frameworks.
This is useful for testing suites, where we want to make Lotus frameworks ready, but not preload applications code.
This allows to test components such as views or actions in isolation and to have faster boot times.
@return [void]
162 163 164 165 166 167 168 |
# File 'lib/lotus/application.rb', line 162 def self.preload! synchronize do applications.each(&:load!) end nil end |
.preload_applications! ⇒ 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.
Full preload for all the registered applications.
This is useful in console where we want all the application code available.
@return [void]
178 179 180 181 182 183 184 |
# File 'lib/lotus/application.rb', line 178 def self.preload_applications! synchronize do applications.each { |app| app.new } end nil end |
Instance Method Details
#call(env) ⇒ Array
Process a request. This method makes Lotus applications compatible with the Rack protocol.
216 217 218 |
# File 'lib/lotus/application.rb', line 216 def call(env) renderer.render(env, middleware.call(env)) end |
#configuration ⇒ 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.
Return the configuration for this application
192 193 194 |
# File 'lib/lotus/application.rb', line 192 def configuration self.class.configuration end |
#middleware ⇒ 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.
Rack middleware stack
228 229 230 |
# File 'lib/lotus/application.rb', line 228 def middleware @middleware ||= configuration.middleware end |
#name ⇒ 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.
Return the application name
200 201 202 |
# File 'lib/lotus/application.rb', line 200 def name self.class.name end |