Class: Hanami::Application
- Inherits:
-
Object
- Object
- Hanami::Application
- Defined in:
- lib/hanami/application.rb
Overview
A full stack Hanami application
Instance Attribute Summary collapse
-
#renderer ⇒ Object
private
Rendering policy.
-
#routes ⇒ Hanami::Router
Return the routes for this application.
Class Method Summary collapse
-
.applications ⇒ Set
private
Registry of Hanami 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 = {}) ⇒ Hanami::Application
constructor
Initialize and load a new instance of the application.
-
#middleware ⇒ Hanami::Middleware
private
Rack middleware stack.
-
#name ⇒ Object
private
Return the application name.
Constructor Details
#initialize(options = {}) ⇒ Hanami::Application
Initialize and load a new instance of the application
73 74 75 76 |
# File 'lib/hanami/application.rb', line 73 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 [Hanami::RenderingPolicy]
66 67 68 |
# File 'lib/hanami/application.rb', line 66 def renderer @renderer end |
#routes ⇒ Hanami::Router
Return the routes for this application
50 51 52 |
# File 'lib/hanami/application.rb', line 50 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 Hanami applications in the current Ruby process
132 133 134 135 136 |
# File 'lib/hanami/application.rb', line 132 def 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
158 159 160 |
# File 'lib/hanami/application.rb', line 158 def 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/hanami/application.rb', line 28 def self.inherited(base) super base.class_eval do include Hanami::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.
194 195 196 |
# File 'lib/hanami/application.rb', line 194 def load!(application = self) Hanami::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 Hanami 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]
210 211 212 213 214 215 216 |
# File 'lib/hanami/application.rb', line 210 def 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]
226 227 228 229 230 231 232 |
# File 'lib/hanami/application.rb', line 226 def preload_applications! synchronize do applications.each { |app| app.new } end nil end |
Instance Method Details
#call(env) ⇒ Array
Process a request. This method makes Hanami applications compatible with the Rack protocol.
108 109 110 |
# File 'lib/hanami/application.rb', line 108 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
84 85 86 |
# File 'lib/hanami/application.rb', line 84 def configuration self.class.configuration end |
#middleware ⇒ Hanami::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
120 121 122 |
# File 'lib/hanami/application.rb', line 120 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
92 93 94 |
# File 'lib/hanami/application.rb', line 92 def name self.class.name end |