Module Merb
In: merb-core/lib/merb-core.rb
merb-core/lib/merb-core/rack.rb
merb-core/lib/merb-core/plugins.rb
merb-core/lib/merb-core/test.rb
merb-core/lib/merb-core/logger.rb
merb-core/lib/merb-core/constants.rb
merb-core/lib/merb-core/server.rb
merb-core/lib/merb-core/dispatch/router.rb
merb-core/lib/merb-core/dispatch/worker.rb
merb-core/lib/merb-core/dispatch/request.rb
merb-core/lib/merb-core/dispatch/default_exception/default_exception.rb
merb-core/lib/merb-core/dispatch/router/behavior.rb
merb-core/lib/merb-core/dispatch/router/route.rb
merb-core/lib/merb-core/dispatch/router/cached_proc.rb
merb-core/lib/merb-core/dispatch/router/resources.rb
merb-core/lib/merb-core/dispatch/dispatcher.rb
merb-core/lib/merb-core/dispatch/request_parsers.rb
merb-core/lib/merb-core/dispatch/cookies.rb
merb-core/lib/merb-core/dispatch/session.rb
merb-core/lib/merb-core/dispatch/session/store_container.rb
merb-core/lib/merb-core/dispatch/session/cookie.rb
merb-core/lib/merb-core/dispatch/session/memcached.rb
merb-core/lib/merb-core/dispatch/session/container.rb
merb-core/lib/merb-core/dispatch/session/memory.rb
merb-core/lib/merb-core/config.rb
merb-core/lib/merb-core/version.rb
merb-core/lib/merb-core/bootloader.rb
merb-core/lib/merb-core/controller/exceptions.rb
merb-core/lib/merb-core/controller/mixins/controller.rb
merb-core/lib/merb-core/controller/mixins/responder.rb
merb-core/lib/merb-core/controller/abstract_controller.rb
merb-core/lib/merb-core/controller/mime.rb
merb-core/lib/merb-core/rack/adapter/abstract.rb
merb-core/lib/merb-core/rack/adapter/webrick.rb
merb-core/lib/merb-core/rack/adapter/thin.rb
merb-core/lib/merb-core/rack/adapter/irb.rb
merb-core/lib/merb-core/rack/adapter/runner.rb
merb-core/lib/merb-core/rack/adapter/thin_turbo.rb
merb-core/lib/merb-core/rack/adapter/fcgi.rb
merb-core/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb
merb-core/lib/merb-core/rack/adapter/evented_mongrel.rb
merb-core/lib/merb-core/rack/adapter/ebb.rb
merb-core/lib/merb-core/rack/adapter/mongrel.rb
merb-core/lib/merb-core/rack/middleware/path_prefix.rb
merb-core/lib/merb-core/rack/middleware/tracer.rb
merb-core/lib/merb-core/rack/middleware/profiler.rb
merb-core/lib/merb-core/rack/middleware/static.rb
merb-core/lib/merb-core/rack/middleware/content_length.rb
merb-core/lib/merb-core/rack/middleware/conditional_get.rb
merb-core/lib/merb-core/rack/middleware.rb
merb-core/lib/merb-core/rack/helpers.rb
merb-core/lib/merb-core/rack/application.rb
merb-core/lib/merb-core/rack/handler/mongrel.rb
merb-core/lib/merb-core/rack/stream_wrapper.rb
merb-core/lib/merb-core/rack/adapter.rb
merb-core/lib/merb-core/autoload.rb
merb-core/lib/merb-core/test/helpers/cookie_jar.rb
merb-core/lib/merb-core/test/helpers/mock_request_helper.rb
merb-core/lib/merb-core/test/helpers/route_helper.rb
merb-core/lib/merb-core/test/helpers/request_helper.rb
merb-core/lib/merb-core/test/helpers/controller_helper.rb
merb-core/lib/merb-core/test/run_specs.rb
merb-core/lib/merb-core/test/test_ext/rspec.rb
merb-core/lib/merb-core/tasks/merb_rake_helper.rb
merb-helpers/lib/merb-helpers.rb
merb-helpers/lib/merb-helpers/tag_helpers.rb
merb-helpers/lib/merb-helpers/date_time_helpers.rb
merb-assets/lib/merb-assets/assets.rb
merb-assets/lib/merb-assets/assets_mixin.rb
merb-slices/lib/generators/templates/full/app/helpers/application_helper.rb
merb-slices/lib/generators/templates/full/spec/spec_helper.rb
merb-slices/lib/merb-slices/controller_mixin.rb
merb-slices/lib/merb-slices/module.rb
merb-slices/lib/merb-slices/module_mixin.rb
merb-param-protection/lib/merb-param-protection.rb

Merb::Plugins.add_rakefiles "merb_param_protection/merbtasks"

Methods

Classes and Modules

Module Merb::<
Module Merb::Assets
Module Merb::AssetsMixin
Module Merb::AuthenticationMixin
Module Merb::ConditionalGetMixin
Module Merb::Const
Module Merb::ControllerExceptions
Module Merb::ControllerMixin
Module Merb::CookiesMixin
Module Merb::Generators
Module Merb::GlobalHelpers
Module Merb::Helpers
Module Merb::InlineTemplates
Module Merb::MemcacheStore
Module Merb::ParamsFilter
Module Merb::Parse
Module Merb::Plugins
Module Merb::Rack
Module Merb::RakeHelper
Module Merb::RenderMixin
Module Merb::ResponderMixin
Module Merb::Session
Module Merb::SessionMixin
Module Merb::Slices
Module Merb::System
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::Counter
Class Merb::Dispatcher
Class Merb::Logger
Class Merb::MemcacheSession
Class Merb::MemorySession
Class Merb::MemorySessionStore
Class Merb::Request
Class Merb::ReservedError
Class Merb::Responder
Class Merb::Router
Class Merb::Server
Class Merb::SessionContainer
Class Merb::SessionStoreContainer
Class Merb::Worker

Constants

VERSION = '1.0.12' unless defined?(Merb::VERSION)
DM_VERSION = '0.9.11' unless defined?(Merb::DM_VERSION)
DO_VERSION = '0.9.11' unless defined?(Merb::DO_VERSION)

External Aliases

environment -> env
  :api: public
started -> started?
  :api: public

Attributes

adapter  [RW]  :api: public
environment  [RW]  :api: public
environment_info  [RW]  :api: private
exiting  [R] 
klass_hashes  [RW]  Set up default variables under Merb
load_paths  [RW]  :api: private
orm  [RW]  Set up default variables under Merb
started  [RW]  :api: private
template_engine  [RW]  Set up default variables under Merb
test_framework  [RW]  Set up default variables under Merb

Public Class methods

Parameters

*generators:Generator paths to add to the list of generators.

Notes

Recommended way to add Generator load paths for plugin authors.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 753
753:     def add_generators(*generators)
754:       @generators ||= []
755:       @generators += generators
756:     end

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

[Source]

    # File merb-core/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 = {})\nself.content_type = :\#{key}\nrender thing, opts\nend\n", __FILE__, __LINE__
92:       
93:       nil
94:     end

Parameters

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

Notes

Recommended way to add Rakefiles load path for plugins authors.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 741
741:     def add_rakefiles(*rakefiles)
742:       @rakefiles ||= []
743:       @rakefiles += rakefiles
744:     end

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

[Source]

    # File merb-core/lib/merb-core.rb, line 85
85:     def at_exit(&blk)
86:       self.at_exit_procs << blk
87:     end

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

[Source]

    # File merb-core/lib/merb-core.rb, line 53
53:     def at_exit_procs
54:       @at_exit_procs ||= []
55:     end

Returns

Hash{String => Symbol}:A hash mapping Content-Type values to the mime type key of the appropriate entry in available_mime_types

:api: public

[Source]

    # File merb-core/lib/merb-core/controller/mime.rb, line 30
30:     def available_accepts
31:       ResponderMixin::MIMES
32:     end

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

[Source]

    # File merb-core/lib/merb-core/controller/mime.rb, line 21
21:     def available_mime_types
22:       ResponderMixin::TYPES
23:     end

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

[Source]

     # File merb-core/lib/merb-core.rb, line 531
531:     def bundled?
532:       $BUNDLE || ENV.key?("BUNDLE")
533:     end

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

[Source]

     # File merb-core/lib/merb-core.rb, line 672
672:     def config(&block)
673:       Merb::Config.configure(&block) if block_given?
674:       Config
675:     end

Returns

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

Notes

Concatenates :deferred_actions configuration option values.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 426
426:     def deferred_actions
427:       @deferred ||= begin
428:         if Merb::Config[:deferred_actions].empty?
429:           /^\0$/
430:         else
431:           /#{Merb::Config[:deferred_actions].join("|")}/
432:         end
433:       end
434:     end

Parameters

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

Returns

String:The directory for the requested type.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 295
295:     def dir_for(type)
296:       Merb.load_paths[type].first
297:     end

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

Parameters

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

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 683
683:     def disable(*components)
684:       disabled_components.push(*components)
685:     end

Returns

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

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 707
707:     def disabled?(*components)
708:       components.all? { |c| disabled_components.include?(c) }
709:     end

Returns

Array:All components that have been disabled.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 699
699:     def disabled_components
700:       Merb::Config[:disabled_components] ||= []
701:     end

Parameters

Array:All components that should be disabled.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 691
691:     def disabled_components=(components)
692:       disabled_components.replace components
693:     end

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

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 643
643:     def env?(env)
644:       Merb.env == env.to_s
645:     end

Required to show exceptions in the log file

e<Exception>:The exception that a message is being generated for

:api: plugin

[Source]

     # File merb-core/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

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

[Source]

    # File merb-core/lib/merb-core.rb, line 64
64:     def exiting=(bool)
65:       Extlib.exiting = bool
66:       @exiting = bool
67:       if bool
68:         if Extlib.const_defined?("Pooling") && Extlib::Pooling.scavenger
69:           Extlib::Pooling.scavenger.wakeup
70:         end
71:         while prc = self.at_exit_procs.pop
72:           prc.call
73:         end unless Merb::Config[:reap_workers_quickly]
74:       end
75:       @exiting
76:     end

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

:api: private

[Source]

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

:api: plugin

[Source]

     # File merb-core/lib/merb-core.rb, line 772
772:     def forking_environment?
773:       !on_windows? && !on_jruby?
774:     end

Returns

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

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 413
413:     def framework_root
414:       @framework_root ||= File.dirname(__FILE__)
415:     end

Returns

Array(String):Paths generators are loaded from

Notes

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

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 730
730:     def generators
731:       @generators ||= []
732:     end

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.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 306
306:     def glob_for(type)
307:       Merb.load_paths[type][1]
308:     end

Load configuration and assign the 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)
: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_stream<IO>:IO handle for logger. Defaults to STDOUT.
:log_file<String>:File path for logger. Overrides :log_stream.
:log_level<Symbol>:logger level, default is :info
: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.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 594
594:     def load_config(options = {})
595:       Merb::Config.setup(Merb::Config.defaults.merge(options))
596:       Merb::BootLoader::Logger.run
597:     end

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<Hash>:Options to pass on to the Merb config.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 609
609:     def load_dependencies(options = {})
610:       load_config(options)
611:       Merb::BootLoader::BuildFramework.run
612:       Merb::BootLoader::Dependencies.run
613:       Merb::BootLoader::BeforeAppLoads.run
614:     end

Returns

String:Path to the log directory which contains the log file.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 402
402:     def log_path
403:       case Merb::Config[:log_file]
404:       when String then File.dirname(Merb::Config[:log_file])
405:       else Merb.root_path("log")
406:       end
407:     end

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

[Source]

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

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

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 348
348:     def logger
349:       Thread.current[:merb_logger] ||= Merb::Logger.new
350:     end

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

[Source]

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

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.

:api: private

[Source]

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

:api: plugin

[Source]

     # File merb-core/lib/merb-core.rb, line 777
777:     def on_jruby?
778:       RUBY_PLATFORM =~ Merb::Const::JAVA_PLATFORM_REGEXP
779:     end

:api: plugin

[Source]

     # File merb-core/lib/merb-core.rb, line 782
782:     def on_windows?
783:       RUBY_PLATFORM =~ Merb::Const::WIN_PLATFORM_REGEXP
784:     end

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

Returns

<Symbol>:default ORM.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 482
482:     def orm
483:       @orm ||= :none
484:     end

@deprecated

[Source]

     # File merb-core/lib/merb-core.rb, line 487
487:     def orm_generator_scope
488:       Merb.logger.warn!("WARNING: Merb.orm_generator_scope is deprecated!")
489:       return :merb_default if Merb.orm == :none
490:       Merb.orm
491:     end

Print a colorized backtrace to the merb logger.

:api: private

[Source]

     # File merb-core/lib/merb-core.rb, line 460
460:     def print_colorized_backtrace(e)      
461:       e.backtrace.map! do |line|
462:         line.gsub(/^#{Merb.framework_root}/, "\e[34mFRAMEWORK_ROOT\e[31m")
463:       end
464:       
465:       Merb.logger.fatal! "\e[34mFRAMEWORK_ROOT\e[0m = #{Merb.framework_root}"
466:       Merb.logger.fatal!
467:       Merb.logger.fatal! "\e[31m#{e.class}: \e[1;31;47m#{e.message}\e[0m"
468:       e.backtrace.each do |line|
469:         Merb.logger.fatal! "\e[31m#{line}\e[0m"
470:       end      
471:     end

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

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 261
261:     def push_path(type, path, file_glob = "**/*.rb")
262:       enforce!(type => Symbol)
263:       load_paths[type] = [path, file_glob]
264:     end

Returns

Array(String):Paths Rakefiles are loaded from.

Notes

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

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 719
719:     def rakefiles
720:       @rakefiles ||= []
721:     end

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

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 620
620:     def reload
621:       Merb::BootLoader::ReloadClasses.reload
622:     end

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

Parameters

key<Symbol>: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

[Source]

     # File merb-core/lib/merb-core/controller/mime.rb, line 115
115:     def remove_mime_type(key)
116:       return false if key == :all
117:       ResponderMixin::TYPES.delete(key)
118:     end

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

Parameters

*args<Array(Symbol)>: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

[Source]

     # File merb-core/lib/merb-core.rb, line 284
284:     def remove_paths(*args)
285:       args.each {|arg| load_paths.delete(arg)}
286:     end

Removes the logger for the current thread (nil).

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 355
355:     def reset_logger!
356:       Thread.current[:merb_logger] = nil
357:     end

Restart the Merb environment explicitly.

Parameters

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

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 193
193:     def restart_environment(argv={})
194:       @started = false
195:       start_environment(Merb::Config.to_hash.merge(argv))
196:     end

Returns

String:The Merb root path.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 314
314:     def root
315:       @root || Merb::Config[:merb_root] || File.expand_path(Dir.pwd)
316:     end

Parameters

value<String>:Path to the root directory.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 322
322:     def root=(value)
323:       @root = value
324:     end

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

[Source]

     # File merb-core/lib/merb-core.rb, line 340
340:     def root_path(*path)
341:       File.join(root, *path)
342:     end

[Source]

     # File merb-core/lib/merb-core.rb, line 786
786:     def run_later(&blk)
787:       Merb::Dispatcher.work_queue << blk
788:     end

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

[Source]

     # File merb-core/lib/merb-core.rb, line 148
148:     def start(argv = ARGV)
149:       Merb::Config[:original_log_stream] = Merb::Config[:log_stream]
150:       Merb::Config[:log_stream] ||= STDOUT
151:       if Hash === argv
152:         Merb::Config.setup(argv)
153:       elsif !argv.nil?
154:         Merb::Config.parse_args(argv)
155:       end
156: 
157:       Merb::Config[:log_stream] = STDOUT
158:       
159:       Merb.environment = Merb::Config[:environment]
160:       Merb.root = Merb::Config[:merb_root]
161: 
162:       case Merb::Config[:action]
163:       when :kill
164:         Merb::Server.kill(Merb::Config[:port], 2)
165:       when :kill_9
166:         Merb::Server.kill(Merb::Config[:port], 9)
167:       when :fast_deploy
168:         Merb::Server.kill("main", "HUP")
169:       else
170:         Merb::Server.start(Merb::Config[:port], Merb::Config[:cluster])
171:         @started = true
172:       end
173:     end

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

[Source]

     # File merb-core/lib/merb-core.rb, line 182
182:     def start_environment(argv=ARGV)
183:       start(argv) unless (@started ||= false)
184:     end

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

Returns

<Symbol>:default template engine.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 515
515:     def template_engine
516:       @template_engine ||= :erb
517:     end

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

Returns

<Symbol>:default test framework.

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 499
499:     def test_framework
500:       @test_framework ||= :rspec
501:     end

@deprecated

[Source]

     # File merb-core/lib/merb-core.rb, line 504
504:     def test_framework_generator_scope
505:       Merb.logger.warn!("WARNING: Merb.test_framework_generator_scope is deprecated")
506:       Merb.test_framework
507:     end

Returns

Boolean:True if Merb environment is testing for instance,

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

:api: public

[Source]

     # File merb-core/lib/merb-core.rb, line 629
629:     def testing?
630:       $TESTING ||= env?(:test) || Merb::Config[:testing]
631:     end

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

[Source]

     # File merb-core/lib/merb-core.rb, line 765
765:     def trap(signal, &block)
766:       if Signal.list.include?(signal)
767:         Kernel.trap(signal, &block) unless Merb.disabled?(:signals)
768:       end
769:     end

Public Instance methods

Construct an app-level path.

@param <Symbol> The type of component. @param *segments<Array[to_s]> Path segments to append.

@return <String>

 A path within the host application, with added segments.

[Source]

    # File merb-slices/lib/generators/templates/full/app/helpers/application_helper.rb, line 47
47:       def app_path_for(type, *segments)
48:         ::<%= module_name %>.app_path_for(type, *segments)
49:       end
50:       
51:       # Construct a slice-level path.
52:       # 
53:       # @param <Symbol> The type of component.
54:       # @param *segments<Array[#to_s]> Path segments to append.
55:       #
56:       # @return <String> 
57:       #  A path within the slice source (Gem), with added segments.
58:       def slice_path_for(type, *segments)
59:         ::<%= module_name %>.slice_path_for(type, *segments)
60:       end

[Validate]