Class: Padrino::Application
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Padrino::Application
- Defined in:
- lib/vendored-middleman-deps/padrino-core-0.11.2/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.
Direct Known Subclasses
AppGem::App, Complex1Demo, Complex2Demo, PadrinoPristine, PadrinoTestApp, PadrinoTestApp2, RenderDemo, SimpleDemo
Class Method Summary collapse
-
.dependencies ⇒ Array
Returns default list of path globs to load as dependencies Appends custom dependency patterns to the be loaded for your Application.
- .inherited(base) ⇒ Object
-
.load_paths ⇒ Array
Directory that need to be added to $LOAD_PATHS from this application.
-
.prerequisites ⇒ Object
An array of file to load before your app.rb, basically are files wich 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).
-
.setup_application! ⇒ TrueClass
Setup the application by registering initializers, load paths and logger Invoked automatically when an application is first instantiated.
Instance Method Summary collapse
-
#logger ⇒ Padrino::Logger
Returns the logger for this application.
Class Method Details
.dependencies ⇒ Array
Returns default list of path globs to load as dependencies Appends custom dependency patterns to the be loaded for your Application
143 144 145 146 147 148 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application.rb', line 143 def dependencies [ 'urls.rb', 'config/urls.rb', 'mailers/*.rb', 'mailers.rb', 'controllers/**/*.rb', 'controllers.rb', 'helpers/**/*.rb', 'helpers.rb' ].map { |file| Dir[File.join(settings.root, file)] }.flatten end |
.inherited(base) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application.rb', line 29 def inherited(base) # @private begun_at = Time.now CALLERS_TO_IGNORE.concat(PADRINO_IGNORE_CALLERS) base.default_configuration! base.prerequisites.concat([ File.join(base.root, '/models.rb'), File.join(base.root, '/models/**/*.rb'), File.join(base.root, '/lib.rb'), File.join(base.root, '/lib/**/*.rb') ]).uniq! Padrino.require_dependencies(base.prerequisites) logger.devel :setup, begun_at, base super(base) # Loading the subclass inherited method end |
.load_paths ⇒ Array
Returns directory that need to be added to $LOAD_PATHS from this application.
128 129 130 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application.rb', line 128 def load_paths @_load_paths ||= %w[models lib mailers controllers helpers].map { |path| File.join(settings.root, path) } end |
.prerequisites ⇒ Object
An array of file to load before your app.rb, basically are files wich 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
164 165 166 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application.rb', line 164 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.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application.rb', line 55 def reload! logger.devel "Reloading #{settings}" reset! # Reset sinatra app reset_router! # Reset all routes Padrino.require_dependencies(settings.app_file, :force => true) # Reload the app file require_dependencies # Reload dependencies default_filters! # Reload filters default_routes! # Reload default routes default_errors! # Reload our errors I18n.reload! if defined?(I18n) # Reload also our translations true end |
.reset_routes! ⇒ TrueClass
Resets application routes to only routes not defined by the user
76 77 78 79 80 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application.rb', line 76 def reset_routes! reset_router! default_routes! true end |
.routes ⇒ Object
Returns the routes of our app.
88 89 90 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application.rb', line 88 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)
118 119 120 121 122 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application.rb', line 118 def run!(={}) return unless Padrino.load! Padrino.mount(settings.to_s).to('/') Padrino.run!() end |
.setup_application! ⇒ TrueClass
Setup the application by registering initializers, load paths and logger Invoked automatically when an application is first instantiated
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application.rb', line 98 def setup_application! return if @_configured settings.require_dependencies settings.default_filters! settings.default_routes! settings.default_errors! if defined?(I18n) I18n.load_path << settings.locale_path I18n.reload! end @_configured = true @_configured end |
Instance Method Details
#logger ⇒ Padrino::Logger
Returns the logger for this application.
23 24 25 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application.rb', line 23 def logger Padrino.logger end |