Class: Padrino::Application

### Home Classes Methods

### In Files

- lib/padrino-core/application.rb

### Parent

Sinatra::Base

### Methods

- ::default
- ::dependencies
- ::inherited
- ::layout_path
- ::load_paths
- ::prerequisites
- ::reload!
- ::require_dependencies
- ::reset_routes!
- ::routes
- ::run!
- ::view_path
- #call
- #logger

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Application
- Padrino::ApplicationLoadError
- Padrino::ApplicationSetup
- Padrino::ApplicationSetup::ClassMethods
- Padrino::AuthenticityToken
- Padrino::Cli
- Padrino::Cli::Adapter
- Padrino::Cli::Base
- Padrino::Cli::Launcher
- Padrino::Filter
- Padrino::Flash
- Padrino::Flash::Helpers
- Padrino::Flash::Storage
- Padrino::Loader
- Padrino::Logger
- Padrino::Logger::Colorize
- Padrino::Logger::Extensions
- Padrino::Logger::Rack
- Padrino::Module
- Padrino::Mounter
- Padrino::Mounter::ApplicationWrapper
- Padrino::Mounter::MounterException
- Padrino::ParamsProtection
- Padrino::ParamsProtection::ClassMethods
- Padrino::ParamsProtection::InstanceMethods
- Padrino::Reloader
- Padrino::Reloader::Rack
- Padrino::Reloader::Storage
- Padrino::Router
- Padrino::Routing
- Padrino::Routing::ClassMethods
- Padrino::Routing::InstanceMethods
- Padrino::Routing::Parent
- Padrino::Routing::UnrecognizedException
- Padrino::Server
- Padrino::ShowExceptions
- Padrino::Tasks
- HttpRouter
- HttpRouter::Node
- HttpRouter::Node::FreeRegex
- HttpRouter::Node::Glob
- HttpRouter::Node::Path
- HttpRouter::Node::SpanningRegex
- HttpRouter::Request
- HttpRouter::Route
- Sinatra
- Sinatra::Base
- Sinatra::Request
- Kernel
- Object
- PadrinoTasks

No matching classes.

# Padrino::Application

Subclasses of this become independent Padrino applications (stemming from Sinatra::Application). These subclassed applications can be easily mounted into other Padrino applications as well.

### Public Class Methods

default(option, *args, &block) click to toggle source

    # File lib/padrino-core/application.rb, line 174
    def default(option, *args, &block)
      set(option, *args, &block) unless respond_to?(option)
    end

dependencies() click to toggle source

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

@return [Array]

    list of path globs to load as dependencies

@example

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

    # File lib/padrino-core/application.rb, line 142
    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) click to toggle source

    # File lib/padrino-core/application.rb, line 43
    def inherited(base)
      begun_at = Time.now
      CALLERS_TO_IGNORE.concat(PADRINO_IGNORE_CALLERS)
      super(base)
      base.prerequisites.replace(self.prerequisites.dup)
      base.default_configuration!
      logger.devel :setup, begun_at, base
    end

layout_path(layout) click to toggle source

Returns an absolute path of application layout.

@example

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

    # File lib/padrino-core/application.rb, line 115
    def layout_path(layout)
      view_path("layouts/#{layout}")
    end

load_paths() click to toggle source

Deprecated

    # File lib/padrino-core/application.rb, line 179
    def load_paths
      warn 'Padrino::Application#load_paths is deprecated. Please, use #prerequisites'
      []
    end

prerequisites() click to toggle source

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

@example Adding a custom prerequisite

    MyApp.prerequisites << Padrino.root('my_app', 'custom_model.rb')

    # File lib/padrino-core/application.rb, line 170
    def prerequisites
      @_prerequisites ||= []
    end

reload!() click to toggle source

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.

@return [TrueClass]

@example

    MyApp.reload!

    # File lib/padrino-core/application.rb, line 63
    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!() click to toggle source

Resets application routes to only routes not defined by the user.

@return [TrueClass]

@example

    MyApp.reset_routes!

    # File lib/padrino-core/application.rb, line 83
    def reset_routes!
      reset_router!
      default_routes
      true
    end

routes() click to toggle source

Returns the routes of our app.

@example

    MyApp.routes

    # File lib/padrino-core/application.rb, line 95
    def routes
      router.routes
    end

run!(options={}) click to toggle source

Run the Padrino app as a self-hosted server using Thin, Mongrel or WEBrick (in that order).

@see Padrino::Server#start

    # File lib/padrino-core/application.rb, line 125
    def run!(options={})
      return unless Padrino.load!
      Padrino.mount(settings.to_s).to('/')
      Padrino.run!(options)
    end

view_path(view) click to toggle source

Returns an absolute path of view in application views folder.

@example

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

    # File lib/padrino-core/application.rb, line 105
    def view_path(view)
      File.expand_path(view, views)
    end

### Protected Class Methods

require_dependencies() click to toggle source

Requires all files within the application load paths.

    # File lib/padrino-core/application.rb, line 189
    def require_dependencies
      Padrino.require_dependencies(dependencies, :force => true)
    end

### Public Instance Methods

call(*args) click to toggle source

    # File lib/padrino-core/application.rb, line 32
    def call(*args)
      settings.init_mutex.synchronize do
        instance_eval{ undef :call }
        class_eval{ alias_method :call, :original_call }
        instance_eval{ undef :original_call }
        super(*args)
      end
    end

logger() click to toggle source

Returns the logger for this application.

@return [Padrino::Logger] Logger associated with this app.

    # File lib/padrino-core/application.rb, line 25
    def logger
      Padrino.logger
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.