Class: Padrino::Application
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Padrino::Application
- Defined in:
- 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.
- .inherited(base) ⇒ Object
-
.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.
-
.require_dependencies ⇒ Object
protected
Requires all files within the application 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 '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 '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 '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 |
.inherited(base) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/padrino-core/application.rb', line 30 def inherited(base) begun_at = Time.now super(base) base.prerequisites.replace(self.prerequisites.dup) base.default_configuration! logger.devel :setup, begun_at, base end |
.layout_path(layout) ⇒ Object
Returns an absolute path of application layout.
105 106 107 |
# File '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 '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 '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 |
.require_dependencies ⇒ Object (protected)
Requires all files within the application load paths.
173 174 175 |
# File 'lib/padrino-core/application.rb', line 173 def require_dependencies Padrino.require_dependencies(dependencies, :force => true) end |
.reset_routes! ⇒ TrueClass
Resets application routes to only routes not defined by the user.
73 74 75 76 77 |
# File '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 '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 '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 '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 'lib/padrino-core/application.rb', line 25 def logger Padrino.logger end |