Class: Padrino::Application
- Defined in:
- padrino-core/lib/padrino-core/application.rb
Overview
Subclasses of this become independent Padrino applications (stemming from Sinatra::Application). These subclassed applications can be easily mounted into other Padrino applications as well.
Class Method Summary collapse
- .callers_to_ignore ⇒ Object
- .default(option, *args, &block) ⇒ Object
-
.dependencies ⇒ Array
Returns default list of path globs to load as dependencies.
-
.layout_path(layout) ⇒ Object
Returns an absolute path of application layout.
-
.prerequisites ⇒ Object
An array of file to load before your app.rb, basically are files which our app depends on.
-
.reload! ⇒ TrueClass
Reloads the application files from all defined load paths.
-
.reset_routes! ⇒ TrueClass
Resets application routes to only routes not defined by the user.
-
.routes ⇒ Object
Returns the routes of our app.
-
.run!(options = {}) ⇒ Object
Run the Padrino app as a self-hosted server using Thin, Mongrel or WEBrick (in that order).
-
.view_path(view) ⇒ Object
Returns an absolute path of view in application views folder.
Instance Method Summary collapse
-
#logger ⇒ Padrino::Logger
Returns the logger for this application.
Class Method Details
.callers_to_ignore ⇒ Object
38 39 40 |
# File 'padrino-core/lib/padrino-core/application.rb', line 38 def callers_to_ignore @callers_to_ignore ||= super + PADRINO_IGNORE_CALLERS end |
.default(option, *args, &block) ⇒ Object
164 165 166 |
# File 'padrino-core/lib/padrino-core/application.rb', line 164 def default(option, *args, &block) set(option, *args, &block) unless respond_to?(option) end |
.dependencies ⇒ Array
Returns default list of path globs to load as dependencies. Appends custom dependency patterns to the be loaded for your Application.
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'padrino-core/lib/padrino-core/application.rb', line 132 def dependencies [ 'urls.rb', 'config/urls.rb', 'mailers/*.rb', 'mailers.rb', 'controllers/**/*.rb', 'controllers.rb', 'helpers/**/*.rb', 'helpers.rb' ].flat_map{ |file| Dir.glob(File.join(settings.root, file)) } end |
.layout_path(layout) ⇒ Object
Returns an absolute path of application layout.
105 106 107 |
# File 'padrino-core/lib/padrino-core/application.rb', line 105 def layout_path(layout) view_path("layouts/#{layout}") end |
.prerequisites ⇒ Object
An array of file to load before your app.rb, basically are files which our app depends on.
By default we look for files:
# List of default files that we are looking for:
yourapp/models.rb
yourapp/models/**/*.rb
yourapp/lib.rb
yourapp/lib/**/*.rb
160 161 162 |
# File 'padrino-core/lib/padrino-core/application.rb', line 160 def prerequisites @_prerequisites ||= [] end |
.reload! ⇒ TrueClass
Reloads the application files from all defined load paths.
This method is used from our Padrino Reloader during development mode in order to reload the source files.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'padrino-core/lib/padrino-core/application.rb', line 53 def reload! logger.devel "Reloading application #{settings}" reset! reset_router! Padrino.require_dependencies(settings.app_file, :force => true) require_dependencies default_routes default_errors I18n.reload! if defined?(I18n) true end |
.reset_routes! ⇒ TrueClass
Resets application routes to only routes not defined by the user.
73 74 75 76 77 |
# File 'padrino-core/lib/padrino-core/application.rb', line 73 def reset_routes! reset_router! default_routes true end |
.routes ⇒ Object
Returns the routes of our app.
85 86 87 |
# File 'padrino-core/lib/padrino-core/application.rb', line 85 def routes router.routes end |
.run!(options = {}) ⇒ Object
Run the Padrino app as a self-hosted server using Thin, Mongrel or WEBrick (in that order).
115 116 117 118 119 |
# File 'padrino-core/lib/padrino-core/application.rb', line 115 def run!(={}) return unless Padrino.load! Padrino.mount(settings.to_s).to('/') Padrino.run!() end |
.view_path(view) ⇒ Object
Returns an absolute path of view in application views folder.
95 96 97 |
# File 'padrino-core/lib/padrino-core/application.rb', line 95 def view_path(view) File.(view, views) end |
Instance Method Details
#logger ⇒ Padrino::Logger
Returns the logger for this application.
25 26 27 |
# File 'padrino-core/lib/padrino-core/application.rb', line 25 def logger Padrino.logger end |