W3cubDocs

/Padrino

Module: Padrino

Extended by:
Configuration, Loader

Overview

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.

Defined Under Namespace

Modules: Admin, ApplicationSetup, Cache, Configuration, Flash, Generators, Helpers, Loader, Mailer, Module, ParamsProtection, PathRouter, Performance, Reloader, Rendering, Routing, Tasks, Utils Classes: Application, AuthenticityToken, Filter, Logger, Mounter, Router, Server

Constant Summary

PADRINO_IGNORE_CALLERS =
[
  %r{lib/padrino-.*$},
  %r{/padrino-.*/(lib|bin)},
  %r{/bin/padrino$},
  %r{/sinatra(/(base|main|show_?exceptions))?\.rb$},
  %r{lib/tilt.*\.rb$},
  %r{lib/rack.*\.rb$},
  %r{lib/mongrel.*\.rb$},
  %r{lib/shotgun.*\.rb$},
  %r{bin/shotgun$},
  %r{\(.*\)},
  %r{shoulda/context\.rb$},
  %r{mocha/integration},
  %r{test/unit},
  %r{rake_test_loader\.rb},
  %r{custom_require\.rb$},
  %r{active_support},
  %r{/thor},
  %r{/lib/bundler},
]
VERSION =
'0.13.2'

Class Attribute Summary

Class Method Summary

Methods included from Loader

after_load, before_load, called_from, clear!, dependency_paths, load!, loaded?, precompile_all_routes!, reload!, require_dependencies

Methods included from Configuration

config, configure

Class Attribute Details

.mounted_root(*args) ⇒ String

Returns the root to the mounted apps base directory.

Parameters:

  • args (Array)

Returns:

  • (String) — the root to the mounted apps base directory.

Class Method Details

.add_middleware(router) ⇒ Object

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

.after_load(&block) ⇒ Object

.application ⇒ Padrino::Router

The resulting rack builder mapping each 'mounted' application.

Returns:

Raises:

  • (ApplicationLoadError) — No applications were mounted.

.before_load(&block) ⇒ Object

.bin(*args) ⇒ Boolean

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

Examples:

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

Parameters:

  • args (Array) — command or commands to execute

Returns:

  • (Boolean)

.bin_gen(*args) ⇒ Object

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

Examples:

Padrino.bin_gen(:app, name.to_s, "-r=#{destination_root}")

Parameters:

  • args. (Array<String>) — Splat of arguments to pass to padrino-gen.

.cache ⇒ Object

Returns the caching engine.

Examples:

# with: Padrino.cache = Padrino::Cache.new(:File, :dir => /my/cache/path)
Padrino.cache['val'] = 'test'
Padrino.cache['val'] # => 'test'
Padrino.cache.delete('val')
Padrino.cache.clear

.cache=(value) ⇒ Object

Set the caching engine.

Examples:

Padrino.cache = Padrino::Cache.new(:LRUHash) # default choice
Padrino.cache = Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) # Keeps cached values in file
Padrino.cache = Padrino::Cache.new(:Memcached) # Uses default server at localhost
Padrino.cache = Padrino::Cache.new(:Memcached, :server => '127.0.0.1:11211', :exception_retry_limit => 1)
Padrino.cache = Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance)
Padrino.cache = Padrino::Cache.new(:Redis) # Uses default server at localhost
Padrino.cache = Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0)
Padrino.cache = Padrino::Cache.new(:Redis, :backend => redis_instance)
Padrino.cache = Padrino::Cache.new(:Mongo) # Uses default server at localhost
Padrino.cache = Padrino::Cache.new(:Mongo, :backend => mongo_client_instance)

# You can manage your cache from anywhere in your app:

Padrino.cache['val'] = 'test'
Padrino.cache['val'] # => 'test'
Padrino.cache.delete('val')
Padrino.cache.clear

Parameters:

  • value — Instance of Moneta store

.clear_middleware! ⇒ Array

Clears all previously configured middlewares.

Returns:

  • (Array) — An empty array

.configure_apps { ... } ⇒ Object

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

Examples:

Padrino.configure_apps do
  enable  :sessions
  disable :raise_errors
end

Yields:

  • The given block will be called to configure each application.

.env ⇒ Symbol

Helper method that return RACK_ENV.

Returns:

  • (Symbol) — The Padrino Environment.

.gem(name, main_module) ⇒ Object

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.

Parameters:

  • name (String) — The name of the gem being registered.
  • main_module (Module) — The main module of the gem.

.gems ⇒ Object

.global_configurations ⇒ Object

Stores global configuration blocks.

.insert_mounted_app(mounter) ⇒ Object

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

Parameters:

.logger ⇒ Padrino::Logger

Examples:

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

Returns:

.logger=(value) ⇒ Object

Set the padrino logger.

Examples:

using ruby default logger
require 'logger'
Padrino.logger = Logger.new(STDOUT)
using ActiveSupport
require 'active_support/buffered_logger'
Padrino.logger = Buffered.new(STDOUT)

Parameters:

  • value (Object) — an object that respond to <<, write, puts, debug, warn etc..

Returns:

  • (Object) — The given value.

.middleware ⇒ Array<Array<Class, Array, Proc>>

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

Returns:

  • (Array<Array<Class, Array, Proc>>) — The middleware classes.

.modules ⇒ Object

.mount(name, options = {}) ⇒ Object

Mounts a new sub-application onto Padrino project.

Examples:

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

See Also:

  • Padrino::Mounter#new

.mounted_apps ⇒ Array

Returns the mounted padrino applications (MountedApp objects)

Returns:

  • (Array) — the mounted padrino applications (MountedApp objects)

.perf_memusage_command ⇒ Object

.root(*args) ⇒ String

Helper method for file references.

Examples:

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

Parameters:

Returns:

  • (String) — The absolute path.

.ruby_command ⇒ String

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

Returns:

  • (String) — path to ruby bin executable

.run!(options = {}) ⇒ Object

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

Examples:

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"

.set_encoding ⇒ NilClass

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.

Returns:

  • (NilClass)

See Also:

.use(mw, *args) { ... } ⇒ Object

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

Parameters:

  • m (Class) — The middleware class.
  • args (Array) — The arguments for the middleware.

Yields:

  • The given block will be passed to the initialized middleware.

.version ⇒ String

The current Padrino version.

Returns:

  • (String) — The version number.

© 2010–2016 Padrino
Licensed under the MIT License.
http://www.rubydoc.info/github/padrino/padrino-framework/Padrino