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
- .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
.default(option, *args, &block) ⇒ Object
161 162 163 |
# File 'padrino-core/lib/padrino-core/application.rb', line 161 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.
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'padrino-core/lib/padrino-core/application.rb', line 129 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.
102 103 104 |
# File 'padrino-core/lib/padrino-core/application.rb', line 102 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
157 158 159 |
# File 'padrino-core/lib/padrino-core/application.rb', line 157 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.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'padrino-core/lib/padrino-core/application.rb', line 50 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.
70 71 72 73 74 |
# File 'padrino-core/lib/padrino-core/application.rb', line 70 def reset_routes! reset_router! default_routes true end |
.routes ⇒ Object
Returns the routes of our app.
82 83 84 |
# File 'padrino-core/lib/padrino-core/application.rb', line 82 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).
112 113 114 115 116 |
# File 'padrino-core/lib/padrino-core/application.rb', line 112 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.
92 93 94 |
# File 'padrino-core/lib/padrino-core/application.rb', line 92 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 |