In Files

Class Index [+]

Quicksearch

Merb

Most of this list is simply constants frozen for efficiency and lowered memory consumption. Every time Ruby VM comes across a string or a number or a regexp literal, new object is created.

This means if you refer to the same string 6 times per request and your application takes 100 requests per second, there are 600 objects for weak MRI garbage collector to work on.

GC cycles take up to 80% (!) time of request processing in some cases. Eventually Rubinius and maybe MRI 2.0 gonna improve this situation but at the moment, all commonly used strings, regexp and numbers used as constants so no extra objects created and VM just operates pointers.


Why do we use Underscores?

In Merb, views are actually methods on controllers. This provides not-insignificant speed benefits, as well as preventing us from needing to copy over instance variables, which we think is proof that everything belongs in one class to begin with.

Unfortunately, this means that view helpers need to be included into the Controller class. To avoid causing confusion when your helpers potentially conflict with our instance methods, we use an _ to disambiguate. As long as you don’t begin your helper methods with _, you only need to worry about conflicts with Merb methods that are part of the public API.

Filters

# is a class method that allows you to specify before filters in your controllers. Filters can either be a symbol or string that corresponds to a method name to call, or a proc object. if it is a method name that method will be called and if it is a proc it will be called with an argument of self where self is the current controller object. When you use a proc as a filter it needs to take one parameter.

# is identical, but the filters are run after the action is invoked.

Examples
  before :some_filter
  before :authenticate, :exclude => [:login, :signup]
  before :has_role, :with => ["Admin"], :exclude => [:index, :show]
  before Proc.new { some_method }, :only => :foo
  before :authorize, :unless => :logged_in?  

You can use either :only => :actionname or :exclude => [:this, :that] but not both at once. :only will only run before the listed actions and :exclude will run for every action that is not listed.

Merb’s before filter chain is very flexible. To halt the filter chain you use throw :halt. If throw is called with only one argument of :halt the return value of the method filters_halted will be what is rendered to the view. You can override filters_halted in your own controllers to control what it outputs. But the throw construct is much more powerful than just that.

throw :halt can also take a second argument. Here is what that second argument can be and the behavior each type can have:

Filter Options (.before, .after, .add_filter, .if, .unless)
:only

A list of actions that this filter should apply to

:exclude

A list of actions that this filter should not apply to

:if

Only apply the filter if the method named after the symbol or calling the proc evaluates to true

:unless

Only apply the filter if the method named after the symbol or calling the proc evaluates to false

:with

Arguments to be passed to the filter. Since we are talking method/proc calls, filter method or Proc should to have the same arity as number of elements in Array you pass to this option.

Types (shortcuts for use in this file)
Filter

String, Proc)]>

params[:action] and params[:controller] deprecated

params[:action] and params[:controller] have been deprecated as of the 0.9.0 release. They are no longer set during dispatch, and have been replaced by action_name and controller_name respectively.


require “time” # httpdate

Public Merb Logger API

To replace an existing logger with a new one:

 Merb.logger.set_log(log{String, IO},level{Symbol, String})
 for example:
 Merb.logger.set_log($stdout, Merb::Logger::Levels[:fatal])

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

Require this rather than autoloading it so we can be sure the default template gets registered

Constants

VERSION

Attributes

exiting[R]
environment[RW]

:api: public

adapter[RW]

:api: public

load_paths[RW]

:api: private

environment_info[RW]

:api: private

started[RW]

:api: private

klass_hashes[RW]

Set up default variables under Merb

orm[RW]

Set up default variables under Merb

test_framework[RW]

Set up default variables under Merb

template_engine[RW]

Set up default variables under Merb

Public Class Methods

add_generators(*generators) click to toggle source

Parameters

*generators

Generator paths to add to the list of generators.

Notes

Recommended way to add Generator load paths for plugin authors.

:api: public

     # File lib/merb-core.rb, line 756
756:     def add_generators(*generators)
757:       @generators ||= []
758:       @generators += generators
759:     end
add_mime_type(key, transform_method, mimes, new_response_headers = {}, default_quality = 1, &block) click to toggle source

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

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.

mimes

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

The response headers to set for the the mime type. For example: ‘Content-Type’ => ‘application/json; charset=utf-8’; As a shortcut for the common charset option, use :charset => ‘utf-8’, which will be correctly appended to the mimetype itself.

&block

a block which recieves the current controller when the format

  is set (in the controller's #content_type method)

Returns

nil

:api: public

    # File lib/merb-core/controller/mime.rb, line 70
70:     def add_mime_type(key, transform_method, mimes, new_response_headers = {}, default_quality = 1, &block) 
71:       enforce!(key => Symbol, mimes => Array)
72:       
73:       content_type = new_response_headers["Content-Type"] || mimes.first
74:       
75:       if charset = new_response_headers.delete(:charset)
76:         content_type += "; charset=#{charset}"
77:       end
78:       
79:       ResponderMixin::TYPES.update(key => 
80:         {:accepts           => mimes, 
81:          :transform_method  => transform_method,
82:          :content_type      => content_type,
83:          :response_headers  => new_response_headers,
84:          :default_quality   => default_quality,
85:          :response_block    => block })
86: 
87:       mimes.each do |mime|
88:         ResponderMixin::MIMES.update(mime => key)
89:       end
90: 
91:       Merb::RenderMixin.class_eval         def render_#{key}(thing = nil, opts = {})          self.content_type = :#{key}          render thing, opts        end, __FILE__, __LINE__
92:       
93:       nil
94:     end
add_rakefiles(*rakefiles) click to toggle source

Parameters

*rakefiles

Rakefile paths to add to the list of Rakefiles.

Notes

Recommended way to add Rakefiles load path for plugins authors.

:api: public

     # File lib/merb-core.rb, line 744
744:     def add_rakefiles(*rakefiles)
745:       @rakefiles ||= []
746:       @rakefiles += rakefiles
747:     end
at_exit(&blk) click to toggle source

Register a proc to run when Merb is exiting gracefully. It will not be run when Merb exits quickly.

Returns

Array

The current list of procs to run when Merb exits gracefully

:api: plugin

    # File lib/merb-core.rb, line 77
77:     def at_exit(&blk)
78:       self.at_exit_procs << blk
79:     end
at_exit_procs() click to toggle source

The list of procs that have been registered with Merb to run when Merb exits gracefully.

Returns

Array

The current list of procs

:api: private

    # File lib/merb-core.rb, line 45
45:     def at_exit_procs
46:       @at_exit_procs ||= []
47:     end
available_accepts() click to toggle source

Returns

Hash{String => Symbol}

A hash mapping Content-Type values to the mime type key of the appropriate entry in #

:api: public

    # File lib/merb-core/controller/mime.rb, line 30
30:     def available_accepts
31:       ResponderMixin::MIMES
32:     end
available_mime_types() click to toggle source

Returns a hash of the available mime types.

Returns

Hash{Symbol => Hash{Symbol => Object}}

The available mime types.

Notes

Each entry corresponds to a call to add_mime_type, having the mime type key (:html, :xml, :json, etc.) as the key and a hash containing the following entries:

  :accepts           # the mime types that will be recognized by this entry
  :transform_method  # the method called on an object to convert it to content of this type (such as to_json)
  :content_type      # the value set to the "Content-Type" HTTP header when this mime is sent in a response
  :response_headers  # sent in a response using this content type
  :default_quality   # the scale factor used in describing content type preference
  :response_block    # the block to be called with the controller when a request responds to this mime type

:api: public

    # File lib/merb-core/controller/mime.rb, line 21
21:     def available_mime_types
22:       ResponderMixin::TYPES
23:     end
bundled?() click to toggle source

Returns

Boolean

True if Merb is running as an application with bundled gems.

Notes

Bundling required gems makes your application independent from the environment it runs in. It is a good practice to freeze application framework and gems and is very useful when application is run in some sort of sandbox, for instance, shared hosting with preconfigured gems.

:api: public

     # File lib/merb-core.rb, line 526
526:     def bundled?
527:       $BUNDLE || ENV.key?("BUNDLE")
528:     end
config(&block) click to toggle source

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
    exception_details  true
    reload_classes     true
    reload_time        0.5
  end

:api: public

     # File lib/merb-core.rb, line 675
675:     def config(&block)
676:       Merb::Config.configure(&block) if block_given?
677:       Config
678:     end
deferred_actions() click to toggle source

Returns

RegExp

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

Notes

Concatenates :deferred_actions configuration option values.

:api: public

     # File lib/merb-core.rb, line 421
421:     def deferred_actions
422:       @deferred ||= begin
423:         if Merb::Config[:deferred_actions].empty?
424:           /^\00$$/
425:         else
426:           /#{Merb::Config[:deferred_actions].join("|")}/
427:         end
428:       end
429:     end
dir_for(type) click to toggle source

Parameters

type

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

Returns

String

The directory for the requested type.

:api: public

     # File lib/merb-core.rb, line 290
290:     def dir_for(type)
291:       Merb.load_paths[type].first
292:     end
disable(*components) click to toggle source

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

Parameters

*args

One or more symbols of Merb internal components.

:api: public

     # File lib/merb-core.rb, line 686
686:     def disable(*components)
687:       disabled_components.push(*components)
688:     end
disabled?(*components) click to toggle source

Returns

Boolean

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

:api: public

     # File lib/merb-core.rb, line 710
710:     def disabled?(*components)
711:       components.all? { |c| disabled_components.include?(c) }
712:     end
disabled_components() click to toggle source

Returns

Array

All components that have been disabled.

:api: public

     # File lib/merb-core.rb, line 702
702:     def disabled_components
703:       Merb::Config[:disabled_components] ||= []
704:     end
disabled_components=(components) click to toggle source

Parameters

Array

All components that should be disabled.

:api: public

     # File lib/merb-core.rb, line 694
694:     def disabled_components=(components)
695:       disabled_components.replace components
696:     end
env?(env) click to toggle source

Ask the question about which environment you’re in.

Parameters

env

Name of the environment to query

Examples

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

:api: public

     # File lib/merb-core.rb, line 646
646:     def env?(env)
647:       Merb.env == env.to_s
648:     end
exception(e) click to toggle source

Required to show exceptions in the log file

e

The exception that a message is being generated for

:api: plugin

     # File lib/merb-core/controller/exceptions.rb, line 346
346:   def self.exception(e)
347:     "#{ e.message } - (#{ e.class })\n" <<  
348:     "#{(e.backtrace or []).join("\n")}" 
349:   end
exiting=(bool) click to toggle source

Set the current exiting state of Merb. Setting this state to true also alerts Extlib to exit and clean up its state.

Returns

Boolean

The current exiting state of Merb

:api: private

    # File lib/merb-core.rb, line 56
56:     def exiting=(bool)
57:       Extlib.exiting = bool
58:       @exiting = bool
59:       if bool
60:         if Extlib.const_defined?("Pooling") && Extlib::Pooling.scavenger
61:           Extlib::Pooling.scavenger.wakeup
62:         end
63:         while prc = self.at_exit_procs.pop
64:           prc.call
65:         end unless Merb::Config[:reap_workers_quickly]
66:       end
67:       @exiting
68:     end
fatal!(str, e = nil) click to toggle source

Perform a hard Exit. Print a backtrace to the merb logger before exiting if verbose is enabled.

:api: private

     # File lib/merb-core.rb, line 435
435:     def fatal!(str, e = nil)
436:       Merb::Config[:log_stream] = STDOUT if STDOUT.tty?
437:       Merb.reset_logger!
438:       
439:       Merb.logger.fatal!
440:       Merb.logger.fatal!("\e[1;31;47mFATAL: #{str}\e[0m")
441:       Merb.logger.fatal!
442: 
443:       print_colorized_backtrace(e) if e && Merb::Config[:verbose]
444:       
445:       if Merb::Config[:show_ugly_backtraces]
446:         raise e
447:       else
448:         exit(1)
449:       end
450:     end
forking_environment?() click to toggle source

:api: plugin

     # File lib/merb-core.rb, line 775
775:     def forking_environment?
776:       !on_windows? && !on_jruby?
777:     end
framework_root() click to toggle source

Returns

String

The path of root directory of the Merb framework.

:api: public

     # File lib/merb-core.rb, line 408
408:     def framework_root
409:       @framework_root ||= File.dirname(__FILE__)
410:     end
generators() click to toggle source

Returns

Array(String)

Paths generators are loaded from

Notes

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

:api: public

     # File lib/merb-core.rb, line 733
733:     def generators
734:       @generators ||= []
735:     end
glob_for(type) click to toggle source

Parameters

type

The type of path to retrieve glob for, e.g. :view.

Returns
String

The pattern with which to match files within the type directory.

:api: public

     # File lib/merb-core.rb, line 301
301:     def glob_for(type)
302:       Merb.load_paths[type][1]
303:     end
load_config(options = {}) click to toggle source

Load configuration and assign the logger.

Parameters

options

Options to pass on to the Merb config.

Options

:host

host to bind to, default is 0.0.0.0.

:port

port to run Merb application on, default is 4000.

:adapter

name of Rack adapter to use, default is “runner“

:rackup

name of Rack init file to use, default is “rack.rb“

:reload_classes

whether Merb should reload classes on each request, default is true

:environment

name of environment to use, default is development

:merb_root

Merb application root, default is Dir.pwd

:use_mutex

turns action dispatch synchronization on or off, default is on (true)

:log_delimiter

what Merb logger uses as delimiter between message sections, default is “ ~ “

:log_auto_flush

whether the log should automatically flush after new messages are added, defaults to true.

:log_stream

IO handle for logger. Defaults to STDOUT.

:log_file

File path for logger. Overrides :log_stream.

:log_level

logger level, default is :info

:disabled_components

array of disabled component names, for instance, to disable json gem, specify :json. Default is empty array.

:deferred_actionsString)]>

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.

:api: public

     # File lib/merb-core.rb, line 597
597:     def load_config(options = {})
598:       Merb::Config.setup(Merb::Config.defaults.merge(options))
599:       Merb::BootLoader::Logger.run
600:     end
load_dependencies(options = {}) click to toggle source

Load all basic dependencies (selected BootLoaders only). This sets up Merb framework component paths (directories for models, controllers, etc) using framework.rb or default layout, loads init file and dependencies specified in it and runs before_app_loads hooks.

Parameters

options

Options to pass on to the Merb config.

:api: public

     # File lib/merb-core.rb, line 612
612:     def load_dependencies(options = {})
613:       load_config(options)
614:       Merb::BootLoader::BuildFramework.run
615:       Merb::BootLoader::Dependencies.run
616:       Merb::BootLoader::BeforeAppLoads.run
617:     end
log_path() click to toggle source

Returns

String

Path to the log directory which contains the log file.

:api: public

     # File lib/merb-core.rb, line 397
397:     def log_path
398:       case Merb::Config[:log_file]
399:       when String then File.dirname(Merb::Config[:log_file])
400:       else Merb.root_path("log")
401:       end
402:     end
log_stream(port = "main") click to toggle source

Returns

String

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

Notes

When Merb.testing? the port is modified to become :test - this keeps this special environment situation from ending up in the memoized @streams just once, thereby never taking changes into account again. Now, it will be memoized as :test - and just logging to merb_test.log.

:api: public

     # File lib/merb-core.rb, line 366
366:     def log_stream(port = "main")
367:       port = :test if Merb.testing?
368:       @streams ||= {}
369:       @streams[port] ||= begin
370:         log = if Merb.testing?
371:           log_path / "merb_test.log"
372:         elsif !Merb::Config[:daemonize] && !Merb::Config[:force_logging]
373:           STDOUT
374:         else
375:           log_path / "merb.#{port}.log"
376:         end
377:         
378:         if log.is_a?(IO)
379:           stream = log
380:         elsif File.exist?(log)
381:           stream = File.open(log, (File::WRONLY | File::APPEND))
382:         else
383:           FileUtils.mkdir_p(File.dirname(log))
384:           stream = File.open(log, (File::WRONLY | File::APPEND | File::CREAT))
385:           stream.write("#{Time.now.httpdate} #{Merb::Config[:log_delimiter]} "              "info #{Merb::Config[:log_delimiter]} Logfile created\n")
386:         end
387:         stream.sync = true
388:         stream
389:       end
390:     end
logger() click to toggle source

Return the Merb Logger object for the current thread. Set it up if it does not exist.

:api: public

     # File lib/merb-core.rb, line 343
343:     def logger
344:       Thread.current[:merb_logger] ||= Merb::Logger.new
345:     end
merge_env(env,use_db=false) click to toggle source

Merge environment settings

This can allow you to have a “localdev” environment that runs like your “development”.

  OR

A “staging” environment that runs identical to your “production” environment.

Examples

From any environment config file (ie, development.rb, custom.rb, localdev.rb, etc).

  staging.rb:
    Merb.merge_env "production"         # We want to use all the settings production uses
    Merb::Config.use do |c|
      c[:log_level]         = "debug"   # except we want debug log level
      c[:log_stream]        = @some_io  # and log to this IO handle
      c[:exception_details] = true      # and we want to see exception details
    end

Parameters

env<~String>

Environment to run like

use_db<~Boolean>

Should Merb use the merged environments DB connection

    Defaults to +false+

:api: public

     # File lib/merb-core.rb, line 103
103:     def merge_env(env,use_db=false)
104:       if Merb.environment_info.nil?
105:         Merb.environment_info = {
106:           :real_env => Merb.environment,
107:           :merged_envs => [],
108:           :db_env => Merb.environment
109:         }
110:       end
111:       
112:       #Only load if it hasn't been loaded
113:       unless Merb.environment_info[:merged_envs].member? env
114:         Merb.environment_info[:merged_envs] << env
115:         
116:         env_file = Merb.dir_for(:config) / "environments" / ("#{env}.rb")
117:         if File.exists?(env_file)
118:           load(env_file)
119:         else
120:           Merb.logger.warn! "Environment file does not exist! #{env_file}"
121:         end
122:       end
123:       
124:       # Mark specific environment to load when ORM loads,
125:       # if multiple environments are loaded, the last one
126:       # with use_db as TRUE will be loaded
127:       if use_db
128:         Merb.environment_info[:db_env] = env
129:       end
130:     end
mime_transform_method(key) click to toggle source

Parameters

key

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.

:api: private

     # File lib/merb-core/controller/mime.rb, line 129
129:     def mime_transform_method(key)
130:       raise ArgumentError, ":#{key} is not a valid MIME-type" unless ResponderMixin::TYPES.key?(key)
131:       ResponderMixin::TYPES[key][:transform_method]
132:     end
on_jruby?() click to toggle source

:api: plugin

     # File lib/merb-core.rb, line 780
780:     def on_jruby?
781:       RUBY_PLATFORM =~ Merb::Const::JAVA_PLATFORM_REGEXP
782:     end
on_windows?() click to toggle source

:api: plugin

     # File lib/merb-core.rb, line 785
785:     def on_windows?
786:       RUBY_PLATFORM =~ Merb::Const::WIN_PLATFORM_REGEXP
787:     end
orm() click to toggle source

Returns the default ORM for this application. For instance, :datamapper.

Returns

default ORM.

:api: public

     # File lib/merb-core.rb, line 477
477:     def orm
478:       @orm ||= :none
479:     end
orm_generator_scope() click to toggle source

@deprecated

     # File lib/merb-core.rb, line 482
482:     def orm_generator_scope
483:       Merb.logger.warn!("WARNING: Merb.orm_generator_scope is deprecated!")
484:       return :merb_default if Merb.orm == :none
485:       Merb.orm
486:     end
push_path(type, path, file_glob = "**/*.rb") click to toggle source

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

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

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

  1. Camping-style “very flat” application layout, where the whole Merb

application and configs are contained within a single file.

Notes

Autoloading for lib uses an 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(:model, Merb.root / “app” / “models”, “*/.rb”) Merb.push_path(:mailer, Merb.root / “app” / “models”, “*/.rb”) Merb.push_path(:controller, Merb.root / “app” / “controllers”, “*/.rb”) Merb.push_path(:view, Merb.root / “app” / “views”, “*/.rb”)

Parameters

type

The type of path being registered (i.e. :view)

path

The full path

file_glob

A glob that will be used to autoload files under the path. Defaults to “*/.rb”.

:api: public

     # File lib/merb-core.rb, line 256
256:     def push_path(type, path, file_glob = "**/*.rb")
257:       enforce!(type => Symbol)
258:       load_paths[type] = [path, file_glob]
259:     end
rakefiles() click to toggle source

Returns

Array(String)

Paths Rakefiles are loaded from.

Notes

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

:api: public

     # File lib/merb-core.rb, line 722
722:     def rakefiles
723:       @rakefiles ||= []
724:     end
reload() click to toggle source

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

:api: public

     # File lib/merb-core.rb, line 623
623:     def reload
624:       Merb::BootLoader::ReloadClasses.reload
625:     end
remove_mime_type(key) click to toggle source

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

Parameters

key

The key that represents the mime-type to remove.

Returns

(Boolean, Hash{Symbol => Object})

If it was present, the old specification of the MIME-type. Same structure

  as a value in Merb.available_mime_types. False if the key was not present.

Notes

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

:api: public

     # File lib/merb-core/controller/mime.rb, line 114
114:     def remove_mime_type(key)
115:       return false if key == :all
116:       ResponderMixin::TYPES.delete(key)
117:     end
remove_paths(*args) click to toggle source

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

Parameters

*args

component(s) 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(:mailer) Merb.push_path(:mailer, Merb.root / “app” / “models”, “*/.rb”)

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

:api: public

     # File lib/merb-core.rb, line 279
279:     def remove_paths(*args)
280:       args.each {|arg| load_paths.delete(arg)}
281:     end
reset_logger!() click to toggle source

Removes the logger for the current thread (nil).

:api: public

     # File lib/merb-core.rb, line 350
350:     def reset_logger!
351:       Thread.current[:merb_logger] = nil
352:     end
restart_environment(argv={}) click to toggle source

Restart the Merb environment explicitly.

Parameters

argv<String, Hash>

The config arguments to restart Merb with. Defaults to +Merb::Config+.

:api: public

     # File lib/merb-core.rb, line 188
188:     def restart_environment(argv={})
189:       @started = false
190:       start_environment(Merb::Config.to_hash.merge(argv))
191:     end
root() click to toggle source

Returns

String

The Merb root path.

:api: public

     # File lib/merb-core.rb, line 309
309:     def root
310:       @root || Merb::Config[:merb_root] || File.expand_path(Dir.pwd)
311:     end
root=(value) click to toggle source

Parameters

value

Path to the root directory.

:api: public

     # File lib/merb-core.rb, line 317
317:     def root=(value)
318:       @root = value
319:     end
root_path(*path) click to toggle source

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"

@public

     # File lib/merb-core.rb, line 335
335:     def root_path(*path)
336:       File.join(root, *path)
337:     end
run_later(&blk) click to toggle source
     # File lib/merb-core.rb, line 789
789:     def run_later(&blk)
790:       Merb::Dispatcher.work_queue << blk
791:     end
running_irb?() click to toggle source

:api: private

     # File lib/merb-core.rb, line 794
794:     def running_irb?
795:       @running_irb
796:     end
start(argv = ARGV) click to toggle source

Start Merb by setting up the Config and then starting the server. Set the Merb application environment and the root path.

Parameters

argv<String, Hash>

The config arguments to start Merb with. Defaults to ARGV.

:api: public

     # File lib/merb-core.rb, line 140
140:     def start(argv = ARGV)
141:       Merb::Config[:original_log_stream] = Merb::Config[:log_stream]
142:       Merb::Config[:log_stream] ||= STDOUT
143:       if Hash === argv
144:         Merb::Config.setup(argv)
145:       elsif !argv.nil?
146:         Merb::Config.parse_args(argv)
147:       end
148: 
149:       # Keep information that we run inside IRB to guard it against overriding in init.rb
150:       @running_irb = Merb::Config[:adapter] == 'irb'
151: 
152:       Merb::Config[:log_stream] = STDOUT
153:       
154:       Merb.environment = Merb::Config[:environment]
155:       Merb.root = Merb::Config[:merb_root]
156: 
157:       case Merb::Config[:action]
158:       when :kill
159:         Merb::Server.kill(Merb::Config[:port], 2)
160:       when :kill_9
161:         Merb::Server.kill(Merb::Config[:port], 9)
162:       when :fast_deploy
163:         Merb::Server.kill("main", "HUP")
164:       else
165:         Merb::Server.start(Merb::Config[:port], Merb::Config[:cluster])
166:         @started = true
167:       end
168:     end
start_environment(argv=ARGV) click to toggle source

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.

:api: public

     # File lib/merb-core.rb, line 177
177:     def start_environment(argv=ARGV)
178:       start(argv) unless (@started ||= false)
179:     end
template_engine() click to toggle source

Returns the default template engine for this application. For instance :haml.

Returns

default template engine.

:api: public

     # File lib/merb-core.rb, line 510
510:     def template_engine
511:       @template_engine ||= :erb
512:     end
test_framework() click to toggle source

Returns the default test framework for this application. For instance :rspec.

Returns

default test framework.

:api: public

     # File lib/merb-core.rb, line 494
494:     def test_framework
495:       @test_framework ||= :rspec
496:     end
test_framework_generator_scope() click to toggle source

@deprecated

     # File lib/merb-core.rb, line 499
499:     def test_framework_generator_scope
500:       Merb.logger.warn!("WARNING: Merb.test_framework_generator_scope is deprecated")
501:       Merb.test_framework
502:     end
testing?() click to toggle source

Returns

Boolean

True if Merb environment is testing for instance,

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

:api: public

     # File lib/merb-core.rb, line 632
632:     def testing?
633:       $TESTING ||= env?(:test) || Merb::Config[:testing]
634:     end
trap(signal, &block) click to toggle source

Install a signal handler for a given signal unless signals have been disabled with Merb.disable(:signals)

Parameters

signal

The name of the signal to install a handler for.

&block

The block to be run when the given signal is received.

:api: public

     # File lib/merb-core.rb, line 768
768:     def trap(signal, &block)
769:       if Signal.list.include?(signal)
770:         Kernel.trap(signal, &block) unless Merb.disabled?(:signals)
771:       end
772:     end
verbose_logging?() click to toggle source

Returns

Boolean

True if Merb is running in debug or verbose mode

:api: public

     # File lib/merb-core.rb, line 534
534:     def verbose_logging?
535:       (ENV['DEBUG'] || $DEBUG || Merb::Config[:verbose]) && Merb.logger
536:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.