Module Merb
In: lib/merb-core/autoload.rb
lib/merb-core/bootloader.rb
lib/merb-core/config.rb
lib/merb-core/constants.rb
lib/merb-core/controller/exceptions.rb
lib/merb-core/controller/mime.rb
lib/merb-core/controller/mixins/controller.rb
lib/merb-core/controller/mixins/responder.rb
lib/merb-core/core_ext/set.rb
lib/merb-core/dispatch/cookies.rb
lib/merb-core/dispatch/request.rb
lib/merb-core/dispatch/router/behavior.rb
lib/merb-core/dispatch/router/cached_proc.rb
lib/merb-core/dispatch/router/route.rb
lib/merb-core/dispatch/router.rb
lib/merb-core/dispatch/session/cookie.rb
lib/merb-core/dispatch/session/memcached.rb
lib/merb-core/dispatch/session/memory.rb
lib/merb-core/dispatch/session.rb
lib/merb-core/logger.rb
lib/merb-core/plugins.rb
lib/merb-core/rack/adapter/ebb.rb
lib/merb-core/rack/adapter/evented_mongrel.rb
lib/merb-core/rack/adapter/fcgi.rb
lib/merb-core/rack/adapter/irb.rb
lib/merb-core/rack/adapter/mongrel.rb
lib/merb-core/rack/adapter/runner.rb
lib/merb-core/rack/adapter/thin.rb
lib/merb-core/rack/adapter/webrick.rb
lib/merb-core/rack/adapter.rb
lib/merb-core/rack/application.rb
lib/merb-core/rack/handler/mongrel.rb
lib/merb-core/rack.rb
lib/merb-core/server.rb
lib/merb-core/test/helpers/controller_helper.rb
lib/merb-core/test/helpers/request_helper.rb
lib/merb-core/test/helpers/route_helper.rb
lib/merb-core/test/helpers/view_helper.rb
lib/merb-core/test.rb
lib/merb-core/version.rb
lib/merb-core.rb

Public Merb Logger API

To replace an existing logger with a new one:

 Merb::Logger.set_log(log{String, IO},level{Symbol, String})

Available logging levels are

  Merb::Logger::{ Fatal, Error, Warn, Info, Debug }

Logging via:

  Merb.logger.fatal(message<String>,&block)
  Merb.logger.error(message<String>,&block)
  Merb.logger.warn(message<String>,&block)
  Merb.logger.info(message<String>,&block)
  Merb.logger.debug(message<String>,&block)

Logging with autoflush:

  Merb.logger.fatal!(message<String>,&block)
  Merb.logger.error!(message<String>,&block)
  Merb.logger.warn!(message<String>,&block)
  Merb.logger.info!(message<String>,&block)
  Merb.logger.debug!(message<String>,&block)

Flush the buffer to

  Merb.logger.flush

Remove the current log object

  Merb.logger.close

Private Merb Logger API

To initialize the logger you create a new object, proxies to set_log.

  Merb::Logger.new(log{String, IO},level{Symbol, String})

Methods

Classes and Modules

Module Merb::AuthenticationMixin
Module Merb::Const
Module Merb::ControllerMixin
Module Merb::GlobalHelpers
Module Merb::InlineTemplates
Module Merb::Plugins
Module Merb::Rack
Module Merb::RenderMixin
Module Merb::ResponderMixin
Module Merb::Template
Module Merb::Test
Class Merb::AbstractController
Class Merb::AcceptType
Class Merb::BootLoader
Class Merb::Config
Class Merb::Controller
Class Merb::CookieSession
Class Merb::Cookies
Class Merb::Dispatcher
Class Merb::Logger
Class Merb::MemCacheSession
Class Merb::MemorySession
Class Merb::MemorySessionContainer
Class Merb::Request
Class Merb::Responder
Class Merb::Router
Class Merb::Server
Class Merb::SimpleSet

Constants

VERSION = '0.9.3' unless defined?(Merb::VERSION)
RELEASE = '' unless defined?(Merb::RELEASE)   Merb::RELEASE meanings: ‘dev’ : unreleased ‘pre’ : pre-release Gem candidates
 nil    : released

You should never check in to trunk with this changed. It should stay ‘dev’. Change it to nil in release tags.

External Aliases

environment -> env

Attributes

adapter  [RW] 
environment  [RW] 
frozen  [RW] 
generator_scope  [RW]  Set up default variables under Merb
klass_hashes  [RW]  Set up default variables under Merb
load_paths  [RW] 
logger  [RW]  Logger settings
logger  [RW] 
registered_session_types  [R] 

Public Class methods

Any specific outgoing headers should be included here. These are not the content-type header but anything in addition to it. transform_method should be set to a symbol of the method used to transform a resource into this mime type. For example for the :xml mime type an object might be transformed by calling :to_xml, or for the :js mime type, :to_json. If there is no transform method, use nil.

Autogenerated Methods

Adding a mime-type adds a render_type method that sets the content type and calls render.

By default this does: def render_all, def render_yaml, def render_text, def render_html, def render_xml, def render_js, and def render_yaml

Parameters

key<Symbol>:The name of the mime-type. This is used by the provides API
transform_method<~to_s>:The associated method to call on objects to convert them to the appropriate mime-type. For instance, :json would use :to_json as its transform_method.
values<Array[String]>:A list of possible values sent in the Accept header, such as text/html, that should be associated with this content-type.
new_response_headers<Hash>:The response headers to set for the the mime type.

Parameters

*rakefiles:Rakefile pathss to add to the list of Rakefiles.

Notes

Recommended way to add Rakefiles load path for plugins authors.

Returns

Hash:The available mime types.

If block was given configures using the block.

Parameters

&block:Configuration parameter block, see example below.

Returns

Hash:The current configuration.

Notes

See Merb::GlobalHelpers.load_config for configuration options list.

Examples

  Merb.config do
    beer               "good"
    hashish            :foo => "bar"
    environment        "development"
    log_level          "debug"
    use_mutex          false
    session_store      "cookie"
    session_secret_key "0d05a226affa226623eb18700"
    exception_details  true
    reload_classes     true
    reload_time        0.5
  end

Returns

RegExp:Regular expression against which deferred actions are matched by Rack application handler.

Notes

Concatenates :deferred_actions configuration option values.

Parameters

type<Symbol>:The type of path to retrieve directory for, e.g. :view.

Returns

String:The directory for the requested type.

Disables the given core components, like a Gem for example.

Parameters

*args:One or more symbols of Merb internal components.

Returns

Boolean:True if all components (or just one) are disabled.

Returns

Array:All components that have been disabled.

Parameters

Array:All components that should be disabled.

Ask the question about which environment you‘re in.

Parameters

env<Symbol, String>:Name of the environment to query

Examples

Merb.env #=> production Merb.env?(:production) #=> true Merb.env?(:development) #=> false

Allows flat apps by setting no default framework directories and yielding a Merb::Router instance. This is optional since the router will automatically configure the app with default routes.

Block parameters

r<Merb::Router::Behavior>:The root behavior upon which new routes can be added.

Returns

String:The path of root directory of the Merb framework.

Used by script/frozen-merb and other freezers to mark Merb as frozen. See Merb::GlobalHelpers.frozen? for more details on framework freezing.

Returns

Boolean:True if Merb is running via script/frozen-merb or other freezer.

Notes

Freezing means bundling framework libraries with your application making it independent from environment it runs in. This is a good practice to freeze application framework and gems it uses and very useful when application is run in some sort of sandbox, for instance, shared hosting with preconfigured gems.

Parameters

type<Symbol>:The type of path to retrieve glob for, e.g. :view.
Returns
String:The pattern with which to match files within the type directory.

Load configuration and assign logger.

Parameters

options<Hash>:Options to pass on to the Merb config.

Options

:host<String>:host to bind to, default is 0.0.0.0.
:port<Fixnum>:port to run Merb application on, default is 4000.
:adapter<String>:name of Rack adapter to use, default is "runner"
:rackup<String>:name of Rack init file to use, default is "rack.rb"
:reload_classes<Boolean>:whether Merb should reload classes on each request, default is true
:environment<String>:name of environment to use, default is development
:merb_root<String>:Merb application root, default is Dir.pwd
:use_mutex<Boolean>:turns action dispatch synchronization on or off, default is on (true)
:session_id_key<String>:session identifier, default is _session_id
:log_delimiter<String>:what Merb logger uses as delimiter between message sections, default is " ~ "
:log_auto_flush<Boolean>:whether the log should automatically flush after new messages are added, defaults to true.
:log_file<IO>:IO for logger. Default is STDOUT.
:log_level<Symbol>:logger level, default is :warn
:disabled_components<Array[Symbol]>:array of disabled component names, for instance, to disable json gem, specify :json. Default is empty array.
:deferred_actions<Array(Symbol, String)]>:names of actions that should be deferred no matter what controller they belong to. Default is empty array.

Some of these options come from command line on Merb application start, some of them are set in Merb init file or environment-specific.

Load all basic dependencies (selected BootLoaders only).

Parameters

options<Hash>:Options to pass on to the Merb config.

Returns

String:The path to the log file. If this Merb instance is running as a daemon this will return STDOUT.

Returns

String:Path to directory that contains the log file.

The mime-type for a particular inbound Accepts header.

Parameters

header<String>:The name of the header to find the mime-type for.

Returns

Hash:The mime type information.

Parameters

key<Symbol>:The key that represents the mime-type.

Returns

Symbol:The transform method for the mime type, e.g. :to_json.

Raises

ArgumentError:The requested mime type is not valid.

This is the core mechanism for setting up your application layout. There are three application layouts in Merb:

Regular app/:type layout of Ruby on Rails fame:

app/models for models app/mailers for mailers (special type of controllers) app/parts for parts, Merb components app/views for templates app/controllers for controller lib for libraries

Flat application layout:

application.rb for models, controllers, mailers, etc config/init.rb for initialization and router configuration config/framework.rb for framework and dependencies configuration views for views

and Camping-style "very flat" application layout, where the whole Merb application and configs fit into a single file.

Notes

Autoloading for lib uses empty glob by default. If you want to have your libraries under lib use autoload, add the following to Merb init file:

Merb.push_path(:lib, Merb.root / "lib", "**/*.rb") # glob set explicity.

Then lib/magicwand/lib/magicwand.rb with MagicWand module will be autoloaded when you first access that constant.

Examples

This method gives you a way to build up your own application structure, for instance, to reflect the structure Rails uses to simplify transition of legacy application, you can set it up like this:

Merb.push_path(:models, Merb.root / "app" / "models", "**/*.rb") Merb.push_path(:mailers, Merb.root / "app" / "models", "**/*.rb") Merb.push_path(:controllers, Merb.root / "app" / "controllers", "**/*.rb") Merb.push_path(:views, Merb.root / "app" / "views", "**/*.rb")

Parameters

type<Symbol>:The type of path being registered (i.e. :view)
path<String>:The full path
file_glob<String>:A glob that will be used to autoload files under the path. Defaults to "**/*.rb".

Returns

Array(String):Paths Rakefiles are loaded from.

Notes

Recommended way to find out what paths Rakefiles are loaded from.

Parameters

name<~to_s>:Name of the session type to register.
file<String>:The file that defines this session type.
description<String>:An optional description of the session type.

Notes

Merb currently supports memory, cookie and memcache session types.

Reload application and framework classes. See Merb::BootLoader::ReloadClasses for details.

Removes a MIME-type from the mime-type list.

Parameters

key<Symbol>:The key that represents the mime-type to remove.

Notes

:all is the key for */*; It can‘t be removed.

Removes given types of application components from load path Merb uses for autoloading.

Parameters

*args<Array(Symbol)>:components names, for instance, :views, :models

Examples

Using this combined with Merb::GlobalHelpers.push_path you can make your Merb application use legacy Rails application components.

Merb.root = "path/to/legacy/app/root" Merb.remove_paths(:mailers) Merb.push_path(:mailers, Merb.root / "app" / "models", "**/*.rb")

Will make Merb use app/models for mailers just like Ruby on Rails does.

Restart the Merb environment explicitly.

Parameters

argv<String, Hash>:The config arguments to restart Merb with. Defaults to +Merb::Config+.

Returns

String:The Merb root path.

Parameters

value<String>:Path to the root directory.

Parameters

*path:The relative path (or list of path components) to a directory under the root of the application.

Returns

String:The full path including the root.

Examples

  Merb.root = "/home/merb/app"
  Merb.path("images") # => "/home/merb/app/images"
  Merb.path("views", "admin") # => "/home/merb/app/views/admin"

Startup Merb by setting up the Config and starting the server. This is where Merb application environment and root path are set.

Parameters

argv<String, Hash>:The config arguments to start Merb with. Defaults to ARGV.

Start the Merb environment, but only if it hasn‘t been loaded yet.

Parameters

argv<String, Hash>:The config arguments to start Merb with. Defaults to ARGV.

Returns

Boolean:True if Merb environment is testing for instance,

Merb is running with RSpec, Test::Unit of other testing facility.

[Validate]