Module: Padrino

### Home Classes Methods

### In Files

- lib/padrino-core.rb
- lib/padrino-core/application.rb
- lib/padrino-core/application/application_setup.rb
- lib/padrino-core/application/authenticity_token.rb
- lib/padrino-core/application/flash.rb
- lib/padrino-core/application/params_protection.rb
- lib/padrino-core/application/routing.rb
- lib/padrino-core/application/show_exceptions.rb
- lib/padrino-core/caller.rb
- lib/padrino-core/cli/adapter.rb
- lib/padrino-core/cli/base.rb
- lib/padrino-core/cli/launcher.rb
- lib/padrino-core/command.rb
- lib/padrino-core/filter.rb
- lib/padrino-core/loader.rb
- lib/padrino-core/logger.rb
- lib/padrino-core/module.rb
- lib/padrino-core/mounter.rb
- lib/padrino-core/reloader.rb
- lib/padrino-core/reloader/rack.rb
- lib/padrino-core/reloader/storage.rb
- lib/padrino-core/router.rb
- lib/padrino-core/server.rb
- lib/padrino-core/tasks.rb
- lib/padrino-core/version.rb

### Namespace

- MODULE Padrino::ApplicationSetup
- MODULE Padrino::Cli
- MODULE Padrino::Flash
- MODULE Padrino::Loader
- MODULE Padrino::Module
- MODULE Padrino::ParamsProtection
- MODULE Padrino::Reloader
- MODULE Padrino::Routing
- MODULE Padrino::Tasks
- CLASS Padrino::Application
- CLASS Padrino::ApplicationLoadError
- CLASS Padrino::AuthenticityToken
- CLASS Padrino::Filter
- CLASS Padrino::Logger
- CLASS Padrino::Mounter
- CLASS Padrino::Router
- CLASS Padrino::Server
- CLASS Padrino::ShowExceptions

### Methods

- ::add_middleware
- ::application
- ::bin
- ::clear_middleware!
- ::configure_apps
- ::env
- ::gem
- ::gems
- ::global_configurations
- ::insert_mounted_app
- ::logger
- ::logger=
- ::middleware
- ::modules
- ::mount
- ::mounted_apps
- ::mounted_root
- ::root
- ::ruby_command
- ::run!
- ::set_encoding
- ::use
- ::version

### 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

Manages current Padrino version for use in gem generation.

We put this in a separate file so you can get padrino version without include full padrino core.

### Constants

PADRINO_IGNORE_CALLERS

  List of callers in a Padrino application that should be ignored as part of a stack trace.

VERSION

  The version constant for the current version of Padrino.

### Attributes

mounted_root[W]

### Public Class Methods

add_middleware(router) click to toggle source

Creates Rack stack with the router added to the middleware chain.

    # File lib/padrino-core.rb, line 120
    def add_middleware(router)
      builder = Rack::Builder.new
      middleware.each{ |mw,args,block| builder.use(mw, *args, &block) }
      builder.run(router)
      builder.to_app
    end

application() click to toggle source

The resulting rack builder mapping each 'mounted' application.

@return [Padrino::Router]

    The router for the application.

@raise [ApplicationLoadError]

    No applications were mounted.

    # File lib/padrino-core.rb, line 68
    def application
      warn 'WARNING! No apps are mounted. Please, mount apps in `config/apps.rb`' unless Padrino.mounted_apps.present?
      router = Padrino::Router.new
      Padrino.mounted_apps.each { |app| app.map_onto(router) }
      middleware.present? ? add_middleware(router) : router
    end

bin(*args) click to toggle source

This method return the correct location of padrino bin or exec it using Kernel#system with the given args.

@param [Array] args

    command or commands to execute

@return [Boolean]

@example

    Padrino.bin('start', '-e production')

    # File lib/padrino-core/command.rb, line 16
    def self.bin(*args)
      @_padrino_bin ||= [self.ruby_command, File.expand_path("../../../bin/padrino", __FILE__)]
      args.empty? ? @_padrino_bin : system(args.unshift(@_padrino_bin).join(" "))
    end

clear_middleware!() click to toggle source

Clears all previously configured middlewares.

@return [Array]

    An empty array

    # File lib/padrino-core.rb, line 144
    def clear_middleware!
      @middleware = []
    end

configure_apps(&block) click to toggle source

Configure Global Project Settings for mounted apps. These can be overloaded in each individual app's own personal configuration. This can be used like:

@yield []

    The given block will be called to configure each application.

@example

    Padrino.configure_apps do
      enable  :sessions
      disable :raise_errors
    end

    # File lib/padrino-core.rb, line 88
    def configure_apps(&block)
      return  unless block_given?
      global_configurations << block
    end

env() click to toggle source

Helper method that return {RACK_ENV}.

@return [Symbol]

    The Padrino Environment.

    # File lib/padrino-core.rb, line 55
    def env
      @_env ||= RACK_ENV.to_s.downcase.to_sym
    end

gem(name, main_module) click to toggle source

Registers a gem with padrino. This relieves the caller from setting up loadpaths by itself and enables Padrino to look up apps in gem folder.

The name given has to be the proper gem name as given in the gemspec.

@param [String] name

    The name of the gem being registered.

@param [Module] main_module

    The main module of the gem.

@returns The root path of the loaded gem

    # File lib/padrino-core.rb, line 177
    def gem(name, main_module)
      _, spec = Gem.loaded_specs.find{|spec_pair| spec_pair[0] == name }
      gems << spec
      modules << main_module
      spec.full_gem_path
    end

gems() click to toggle source

@returns [Gem::Specification]

    # File lib/padrino-core.rb, line 186
    def gems
      @gems ||= []
    end

global_configurations() click to toggle source

Stores global configuration blocks.

    # File lib/padrino-core.rb, line 96
    def global_configurations
      @_global_configurations ||= []
    end

insert_mounted_app(mounter) click to toggle source

Inserts a Mounter object into the mounted applications (avoids duplicates).

@param [Padrino::Mounter] mounter

    # File lib/padrino-core/mounter.rb, line 292
    def insert_mounted_app(mounter)
      Padrino.mounted_apps.push(mounter) unless Padrino.mounted_apps.include?(mounter)
    end

logger() click to toggle source

@return [Padrino::Logger]

@example

    logger.debug "foo"
    logger.warn "bar"

    # File lib/padrino-core/logger.rb, line 15
    def self.logger
      Padrino::Logger.logger
    end

logger=(value) click to toggle source

Set the padrino logger.

@param [Object] value

    an object that respond to <<, write, puts, debug, warn etc..

@return [Object]

    The given value.

@example using ruby default logger

    require 'logger'
    Padrino.logger = Logger.new(STDOUT)

@example using ActiveSupport

    require 'active_support/buffered_logger'
    Padrino.logger = Buffered.new(STDOUT)

    # File lib/padrino-core/logger.rb, line 36
    def self.logger=(value)
      Padrino::Logger.logger = value
    end

middleware() click to toggle source

A Rack::Builder object that allows to add middlewares in front of all Padrino applications.

@return [Array<Array<Class, Array, Proc>>]

    The middleware classes.

    # File lib/padrino-core.rb, line 134
    def middleware
      @middleware ||= []
    end

modules() click to toggle source

@returns [<Padrino::Module>]

    # File lib/padrino-core.rb, line 192
    def modules
      @modules ||= []
    end

mount(name, options={}) click to toggle source

Mounts a new sub-application onto Padrino project.

@see Padrino::Mounter#new

@example

    Padrino.mount("blog_app").to("/blog")

    # File lib/padrino-core/mounter.rb, line 304
    def mount(name, options={})
      Mounter.new(name, options)
    end

mounted_apps() click to toggle source

@return [Array]

    the mounted padrino applications (MountedApp objects)

    # File lib/padrino-core/mounter.rb, line 283
    def mounted_apps
      @mounted_apps ||= []
    end

mounted_root(*args) click to toggle source

@param [Array] args

@return [String]

    the root to the mounted apps base directory.

    # File lib/padrino-core/mounter.rb, line 275
    def mounted_root(*args)
      Padrino.root(@mounted_root ||= "", *args)
    end

root(*args) click to toggle source

Helper method for file references.

@param [Array<String>] args

    The directories to join to {PADRINO_ROOT}.

@return [String]

    The absolute path.

@example

    # Referencing a file in config called settings.yml
    Padrino.root("config", "settings.yml")
    # returns PADRINO_ROOT + "/config/setting.yml"

    # File lib/padrino-core.rb, line 45
    def root(*args)
      File.expand_path(File.join(PADRINO_ROOT, *args))
    end

ruby_command() click to toggle source

Return the path to the ruby interpreter taking into account multiple installations and windows extensions.

@return [String]

    path to ruby bin executable

    # File lib/padrino-core/command.rb, line 28
    def self.ruby_command
      @ruby_command ||= begin
        ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
        ruby << RbConfig::CONFIG['EXEEXT']

        # escape string in case path to ruby executable contain spaces.
        ruby.sub!(/.*\s.*/, '"\&"')
        ruby
      end
    end

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

Runs the Padrino apps as a self-hosted server using: thin, mongrel, or WEBrick in that order.

@example

    Padrino.run! # with these defaults => host: "127.0.0.1", port: "3000", adapter: the first found
    Padrino.run!("0.0.0.0", "4000", "mongrel") # use => host: "0.0.0.0", port: "4000", adapter: "mongrel"

    # File lib/padrino-core/server.rb, line 10
    def self.run!(options={})
      Padrino.load!
      Server.start(*detect_application(options))
    end

set_encoding() click to toggle source

Set `Encoding.default_internal` and `Encoding.default_external` to +Encoding::UFT_8+.

Please note that in `1.9.2` with some template engines like `haml` you should turn off Encoding.default_internal to prevent problems.

@see github.com/rtomayko/tilt/issues/75

@return [NilClass]

    # File lib/padrino-core.rb, line 111
    def set_encoding
      Encoding.default_external = Encoding::UTF_8
      Encoding.default_internal = Encoding::UTF_8
      nil
    end

use(mw, *args, &block) click to toggle source

Convenience method for adding a Middleware to the whole padrino app.

@param [Class] m

    The middleware class.

@param [Array] args

    The arguments for the middleware.

@yield []

    The given block will be passed to the initialized middleware.

    # File lib/padrino-core.rb, line 160
    def use(mw, *args, &block)
      middleware << [mw, args, block]
    end

version() click to toggle source

The current Padrino version.

@return [String]

    The version number.

    # File lib/padrino-core/version.rb, line 17
    def self.version
      VERSION
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.