Class: Padrino::Application

Inherits:
Sinatra::Base
  • Object
show all
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

Instance Method Summary collapse

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

.dependenciesArray

Returns default list of path globs to load as dependencies. Appends custom dependency patterns to the be loaded for your Application.

Examples:

MyApp.dependencies << "#{Padrino.root}/uploaders/**/*.rb"
MyApp.dependencies << Padrino.root('other_app', 'controllers.rb')

Returns:

  • (Array)

    list of path globs to load as dependencies



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.

Examples:

Admin.layout_path :application #=> "/home/user/test/admin/views/layouts/application"


102
103
104
# File 'padrino-core/lib/padrino-core/application.rb', line 102

def layout_path(layout)
  view_path("layouts/#{layout}")
end

.prerequisitesObject

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

Examples:

Adding a custom prerequisite

MyApp.prerequisites << Padrino.root('my_app', 'custom_model.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.

Examples:

MyApp.reload!

Returns:

  • (TrueClass)


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.

Examples:

MyApp.reset_routes!

Returns:

  • (TrueClass)


70
71
72
73
74
# File 'padrino-core/lib/padrino-core/application.rb', line 70

def reset_routes!
  reset_router!
  default_routes
  true
end

.routesObject

Returns the routes of our app.

Examples:

MyApp.routes


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).

See Also:



112
113
114
115
116
# File 'padrino-core/lib/padrino-core/application.rb', line 112

def run!(options={})
  return unless Padrino.load!
  Padrino.mount(settings.to_s).to('/')
  Padrino.run!(options)
end

.view_path(view) ⇒ Object

Returns an absolute path of view in application views folder.

Examples:

Admin.view_path 'users/index' #=> "/home/user/test/admin/views/users/index"


92
93
94
# File 'padrino-core/lib/padrino-core/application.rb', line 92

def view_path(view)
  File.expand_path(view, views)
end

Instance Method Details

#loggerPadrino::Logger

Returns the logger for this application.

Returns:



25
26
27
# File 'padrino-core/lib/padrino-core/application.rb', line 25

def logger
  Padrino.logger
end