Module: Merb
- Defined in:
- lib/merb-core/constants.rb,
lib/merb-core.rb,
lib/merb-core/rack.rb,
lib/merb-core/test.rb,
lib/merb-core/config.rb,
lib/merb-core/server.rb,
lib/merb-core/plugins.rb,
lib/merb-core/version.rb,
lib/merb-core/autoload.rb,
lib/merb-core/autoload.rb,
lib/merb-core/bootloader.rb,
lib/merb-core/rack/adapter.rb,
lib/merb-core/controller/mime.rb,
lib/merb-core/dispatch/router.rb,
lib/merb-core/dispatch/worker.rb,
lib/merb-core/rack/middleware.rb,
lib/merb-core/dispatch/cookies.rb,
lib/merb-core/dispatch/request.rb,
lib/merb-core/dispatch/session.rb,
lib/merb-core/rack/adapter/ebb.rb,
lib/merb-core/rack/adapter/irb.rb,
lib/merb-core/rack/application.rb,
lib/merb-core/rack/adapter/fcgi.rb,
lib/merb-core/rack/adapter/thin.rb,
lib/merb-core/dispatch/dispatcher.rb,
lib/merb-core/rack/adapter/runner.rb,
lib/merb-core/rack/adapter/mongrel.rb,
lib/merb-core/rack/adapter/webrick.rb,
lib/merb-core/rack/middleware/csrf.rb,
lib/merb-core/controller/exceptions.rb,
lib/merb-core/dispatch/router/route.rb,
lib/merb-core/rack/middleware/static.rb,
lib/merb-core/rack/middleware/tracer.rb,
lib/merb-core/dispatch/session/cookie.rb,
lib/merb-core/dispatch/session/memory.rb,
lib/merb-core/rack/adapter/thin_turbo.rb,
lib/merb-core/dispatch/router/behavior.rb,
lib/merb-core/rack/middleware/profiler.rb,
lib/merb-core/test/helpers/view_helper.rb,
lib/merb-core/test/helpers/route_helper.rb,
lib/merb-core/dispatch/session/container.rb,
lib/merb-core/dispatch/session/memcached.rb,
lib/merb-core/controller/mixins/responder.rb,
lib/merb-core/dispatch/router/cached_proc.rb,
lib/merb-core/rack/middleware/path_prefix.rb,
lib/merb-core/test/helpers/request_helper.rb,
lib/merb-core/controller/mixins/controller.rb,
lib/merb-core/rack/adapter/evented_mongrel.rb,
lib/merb-core/rack/middleware/content_length.rb,
lib/merb-core/test/helpers/controller_helper.rb,
lib/merb-core/rack/middleware/conditional_get.rb,
lib/merb-core/dispatch/session/store_container.rb,
lib/merb-core/rack/adapter/swiftiplied_mongrel.rb,
lib/merb-core/dispatch/default_exception/default_exception.rb,
lib/merb-core/rack/handler/mongrel.rb
Overview
Most of this list is simply constants frozen for efficiency
Defined Under Namespace
Modules: AuthenticationMixin, ConditionalGetMixin, Const, ControllerExceptions, ControllerMixin, CookiesMixin, GlobalHelpers, InlineTemplates, MemcacheStore, Plugins, Rack, RenderMixin, ResponderMixin, Session, SessionMixin, Template, Test Classes: AcceptType, BootLoader, Config, Controller, CookieSession, Cookies, Dispatcher, MemcacheSession, MemorySession, MemorySessionStore, Request, Responder, Router, Server, SessionContainer, SessionStoreContainer, Worker
Constant Summary collapse
- Logger =
Extlib::Logger
- VERSION =
'0.9.7'
- 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.
'dev'
Class Attribute Summary collapse
-
.adapter ⇒ Object
Returns the value of attribute adapter.
-
.environment ⇒ Object
(also: env)
Returns the value of attribute environment.
-
.environment_info ⇒ Object
Returns the value of attribute environment_info.
-
.klass_hashes ⇒ Object
Set up default variables under Merb.
-
.load_paths ⇒ Object
Returns the value of attribute load_paths.
-
.logger ⇒ Object
Logger settings.
-
.orm ⇒ Object
Returns the default ORM for this application.
-
.started ⇒ Object
(also: started?)
Returns the value of attribute started.
-
.template_engine ⇒ Object
Returns the default template engine for this application.
-
.test_framework ⇒ Object
Returns the default test framework for this application.
Class Method Summary collapse
-
.add_generators(*generators) ⇒ Object
Parameters *generators:: Generator paths to add to the list of generators.
-
.add_mime_type(key, transform_method, mimes, new_response_headers = {}, default_quality = 1, &block) ⇒ Object
Any specific outgoing headers should be included here.
-
.add_rakefiles(*rakefiles) ⇒ Object
Parameters *rakefiles:: Rakefile pathss to add to the list of Rakefiles.
-
.available_mime_types ⇒ Object
Returns Hash:: The available mime types.
-
.bundled? ⇒ Boolean
Returns Boolean:: True if Merb is running as an application with bundled gems.
-
.config(&block) ⇒ Object
If block was given configures using the block.
-
.deferred_actions ⇒ Object
Returns RegExp:: Regular expression against which deferred actions are matched by Rack application handler.
-
.dir_for(type) ⇒ Object
Parameters type<Symbol>:: The type of path to retrieve directory for, e.g.
-
.disable(*components) ⇒ Object
Disables the given core components, like a Gem for example.
-
.disabled?(*components) ⇒ Boolean
Returns Boolean:: True if all components (or just one) are disabled.
-
.disabled_components ⇒ Object
Returns Array:: All components that have been disabled.
-
.disabled_components=(components) ⇒ Object
Parameters Array:: All components that should be disabled.
-
.env?(env) ⇒ Boolean
Ask the question about which environment you’re in.
-
.exception(e) ⇒ Object
Required to show exceptions in the log file.
-
.flat!(framework = {}) ⇒ Object
Allows flat apps by setting no default framework directories and yielding a Merb::Router instance.
-
.framework_root ⇒ Object
Returns String:: The path of root directory of the Merb framework.
-
.generators ⇒ Object
Returns Array(String):: Paths generators are loaded from.
-
.glob_for(type) ⇒ Object
Parameters type<Symbol>:: The type of path to retrieve glob for, e.g.
-
.load_config(options = {}) ⇒ Object
Load configuration and assign logger.
-
.load_dependencies(options = {}) ⇒ Object
Load all basic dependencies (selected BootLoaders only).
-
.log_file ⇒ Object
Returns String:: The path to the log file.
-
.log_path ⇒ Object
Returns String:: Path to directory that contains the log file.
-
.merge_env(env, use_db = false) ⇒ Object
Merge environment settings Can allow you to have a “localdev” that runs like your “development” OR A “staging” environment that runs like your “production”.
-
.mime_by_request_header(header) ⇒ Object
The mime-type for a particular inbound Accepts header.
-
.mime_transform_method(key) ⇒ Object
Parameters key<Symbol>:: The key that represents the mime-type.
- .orm_generator_scope ⇒ Object deprecated Deprecated.
-
.push_path(type, path, file_glob = "**/*.rb") ⇒ Object
This is the core mechanism for setting up your application layout.
-
.rakefiles ⇒ Object
Returns Array(String):: Paths Rakefiles are loaded from.
-
.reload ⇒ Object
Reload application and framework classes.
-
.remove_mime_type(key) ⇒ Object
Removes a MIME-type from the mime-type list.
-
.remove_paths(*args) ⇒ Object
Removes given types of application components from load path Merb uses for autoloading.
-
.restart_environment(argv = {}) ⇒ Object
Restart the Merb environment explicitly.
-
.root ⇒ Object
Returns String:: The Merb root path.
-
.root=(value) ⇒ Object
Parameters value<String>:: Path to the root directory.
-
.root_path(*path) ⇒ Object
Parameters *path:: The relative path (or list of path components) to a directory under the root of the application.
-
.start(argv = ARGV) ⇒ Object
Startup Merb by setting up the Config and starting the server.
-
.start_environment(argv = ARGV) ⇒ Object
Start the Merb environment, but only if it hasn’t been loaded yet.
- .test_framework_generator_scope ⇒ Object deprecated Deprecated.
-
.testing? ⇒ Boolean
Returns Boolean:: True if Merb environment is testing for instance, Merb is running with RSpec, Test::Unit of other testing facility.
Class Attribute Details
.adapter ⇒ Object
Returns the value of attribute adapter.
134 135 136 |
# File 'lib/merb-core.rb', line 134 def adapter @adapter end |
.environment ⇒ Object Also known as: env
Returns the value of attribute environment.
134 135 136 |
# File 'lib/merb-core.rb', line 134 def environment @environment end |
.environment_info ⇒ Object
Returns the value of attribute environment_info.
134 135 136 |
# File 'lib/merb-core.rb', line 134 def environment_info @environment_info end |
.klass_hashes ⇒ Object
Set up default variables under Merb
333 334 335 |
# File 'lib/merb-core.rb', line 333 def klass_hashes @klass_hashes end |
.load_paths ⇒ Object
Returns the value of attribute load_paths.
134 135 136 |
# File 'lib/merb-core.rb', line 134 def load_paths @load_paths end |
.logger ⇒ Object
Logger settings
265 266 267 |
# File 'lib/merb-core.rb', line 265 def logger @logger end |
.orm ⇒ Object
Returns the default ORM for this application. For instance, :datamapper.
Returns
- <Symbol>
-
default ORM.
333 334 335 |
# File 'lib/merb-core.rb', line 333 def orm @orm end |
.started ⇒ Object Also known as: started?
Returns the value of attribute started.
134 135 136 |
# File 'lib/merb-core.rb', line 134 def started @started end |
.template_engine ⇒ Object
Returns the default template engine for this application. For instance :haml.
Returns
- <Symbol>
-
default template engine.
333 334 335 |
# File 'lib/merb-core.rb', line 333 def template_engine @template_engine end |
.test_framework ⇒ Object
Returns the default test framework for this application. For instance :rspec.
Returns
- <Symbol>
-
default test framework.
333 334 335 |
# File 'lib/merb-core.rb', line 333 def test_framework @test_framework end |
Class Method Details
.add_generators(*generators) ⇒ Object
Parameters
- *generators
-
Generator paths to add to the list of generators.
Notes
Recommended way to add Generator load paths for plugin authors.
575 576 577 578 |
# File 'lib/merb-core.rb', line 575 def add_generators(*generators) @generators ||= [] @generators += generators end |
.add_mime_type(key, transform_method, mimes, new_response_headers = {}, default_quality = 1, &block) ⇒ Object
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>
-
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)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/merb-core/controller/mime.rb', line 41 def add_mime_type(key, transform_method, mimes, new_response_headers = {}, default_quality = 1, &block) enforce!(key => Symbol, mimes => Array) content_type = new_response_headers["Content-Type"] || mimes.first if charset = new_response_headers.delete(:charset) content_type += "; charset=#{charset}" end ResponderMixin::TYPES.update(key => {:accepts => mimes, :transform_method => transform_method, :content_type => content_type, :response_headers => new_response_headers, :default_quality => default_quality, :response_block => block }) mimes.each do |mime| ResponderMixin::MIMES.update(mime => key) end Merb::RenderMixin.class_eval <<-EOS, __FILE__, __LINE__ def render_#{key}(thing = nil, opts = {}) self.content_type = :#{key} render thing, opts end EOS end |
.add_rakefiles(*rakefiles) ⇒ Object
Parameters
- *rakefiles
-
Rakefile pathss to add to the list of Rakefiles.
Notes
Recommended way to add Rakefiles load path for plugins authors.
565 566 567 568 |
# File 'lib/merb-core.rb', line 565 def add_rakefiles(*rakefiles) @rakefiles ||= ['merb-core/test/tasks/spectasks'] @rakefiles += rakefiles end |
.available_mime_types ⇒ Object
Returns
- Hash
-
The available mime types.
6 7 8 |
# File 'lib/merb-core/controller/mime.rb', line 6 def available_mime_types ResponderMixin::TYPES end |
.bundled? ⇒ Boolean
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. 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.
382 383 384 |
# File 'lib/merb-core.rb', line 382 def bundled? $BUNDLE || ENV.key?("BUNDLE") end |
.config(&block) ⇒ Object
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
509 510 511 512 |
# File 'lib/merb-core.rb', line 509 def config(&block) Merb::Config.configure(&block) if block_given? Config end |
.deferred_actions ⇒ Object
Returns
- RegExp
-
Regular expression against which deferred actions are matched by Rack application handler.
Notes
Concatenates :deferred_actions configuration option values.
306 307 308 309 310 311 312 313 314 |
# File 'lib/merb-core.rb', line 306 def deferred_actions @deferred ||= begin if Merb::Config[:deferred_actions].empty? /^\0$/ else /#{Merb::Config[:deferred_actions].join("|")}/ end end end |
.dir_for(type) ⇒ Object
Parameters
- type<Symbol>
-
The type of path to retrieve directory for, e.g. :view.
Returns
- String
-
The directory for the requested type.
221 222 223 |
# File 'lib/merb-core.rb', line 221 def dir_for(type) Merb.load_paths[type].first end |
.disable(*components) ⇒ Object
Disables the given core components, like a Gem for example.
Parameters
- *args
-
One or more symbols of Merb internal components.
518 519 520 |
# File 'lib/merb-core.rb', line 518 def disable(*components) disabled_components.push(*components) end |
.disabled?(*components) ⇒ Boolean
Returns
- Boolean
-
True if all components (or just one) are disabled.
536 537 538 |
# File 'lib/merb-core.rb', line 536 def disabled?(*components) components.all? { |c| disabled_components.include?(c) } end |
.disabled_components ⇒ Object
Returns
- Array
-
All components that have been disabled.
530 531 532 |
# File 'lib/merb-core.rb', line 530 def disabled_components Merb::Config[:disabled_components] ||= [] end |
.disabled_components=(components) ⇒ Object
Parameters
- Array
-
All components that should be disabled.
524 525 526 |
# File 'lib/merb-core.rb', line 524 def disabled_components=(components) disabled_components.replace components end |
.env?(env) ⇒ Boolean
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
482 483 484 |
# File 'lib/merb-core.rb', line 482 def env?(env) Merb.env == env.to_s end |
.exception(e) ⇒ Object
Required to show exceptions in the log file
- e<Exception>
-
The exception that a message is being generated for
310 311 312 313 |
# File 'lib/merb-core/controller/exceptions.rb', line 310 def self.exception(e) "#{ e. } - (#{ e.class })\n" << "#{(e.backtrace or []).join("\n")}" end |
.flat!(framework = {}) ⇒ Object
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.
323 324 325 326 327 328 329 330 |
# File 'lib/merb-core.rb', line 323 def flat!(framework = {}) Merb::Config[:framework] = framework Merb::Router.prepare do |r| yield(r) if block_given? r.default_routes end end |
.framework_root ⇒ Object
Returns
- String
-
The path of root directory of the Merb framework.
294 295 296 |
# File 'lib/merb-core.rb', line 294 def framework_root @framework_root ||= File.dirname(__FILE__) end |
.generators ⇒ Object
Returns
- Array(String)
-
Paths generators are loaded from
Notes
Recommended way to find out what paths generators are loaded from.
556 557 558 |
# File 'lib/merb-core.rb', line 556 def generators @generators ||= [] end |
.glob_for(type) ⇒ Object
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.
230 231 232 |
# File 'lib/merb-core.rb', line 230 def glob_for(type) Merb.load_paths[type][1] end |
.load_config(options = {}) ⇒ Object
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)
- :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>
-
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.
441 442 443 444 |
# File 'lib/merb-core.rb', line 441 def load_config( = {}) Merb::Config.setup({ :log_file => STDOUT, :log_level => :warn, :log_auto_flush => true }.merge()) Merb::BootLoader::Logger.run end |
.load_dependencies(options = {}) ⇒ Object
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.
454 455 456 457 458 459 |
# File 'lib/merb-core.rb', line 454 def load_dependencies( = {}) load_config() Merb::BootLoader::BuildFramework.run Merb::BootLoader::Dependencies.run Merb::BootLoader::BeforeAppLoads.run end |
.log_file ⇒ Object
Returns
- String
-
The path to the log file. If this Merb instance is running as a daemon this will return
STDOUT
.
271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/merb-core.rb', line 271 def log_file if Merb::Config[:log_file] Merb::Config[:log_file] elsif Merb.testing? log_path / "merb_test.log" elsif !(Merb::Config[:daemonize] || Merb::Config[:cluster]) STDOUT else log_path / "merb.#{Merb::Config[:port]}.log" end end |
.log_path ⇒ Object
Returns
- String
-
Path to directory that contains the log file.
285 286 287 288 289 290 |
# File 'lib/merb-core.rb', line 285 def log_path case Merb::Config[:log_file] when String then File.dirname(Merb::Config[:log_file]) else Merb.root_path("log") end end |
.merge_env(env, use_db = false) ⇒ Object
Merge environment settings Can allow you to have a “localdev” that runs like your “development”
OR
A “staging” environment that runs like your “production”
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 { |c|
c[:log_level] = "debug" #except we want debug log level
c[:exception_details] = true #and we want to see exception details
}
Parameters
- env<~String>
-
Environment to run like
- use_db<~Boolean>
-
Should Merb use the merged environments DB connection
Defaults to +false+
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/merb-core.rb', line 57 def merge_env(env,use_db=false) if Merb.environment_info.nil? Merb.environment_info = { :real_env => Merb.environment, :merged_envs => [], :db_env => Merb.environment } end #Only load if it hasn't been loaded unless Merb.environment_info[:merged_envs].member? env Merb.environment_info[:merged_envs] << env env_file = Merb.dir_for(:config) / "environments" / ("#{env}.rb") if File.exists?(env_file) load(env_file) else Merb.logger.warn! "Environment file does not exist! #{env_file}" end end # Mark specific environment to load when ORM loads, # if multiple environments are loaded, the last one # with use_db as TRUE will be loaded if use_db Merb.environment_info[:db_env] = env end end |
.mime_by_request_header(header) ⇒ Object
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.
102 103 104 |
# File 'lib/merb-core/controller/mime.rb', line 102 def mime_by_request_header(header) available_mime_types.find {|key,info| info[:accepts].include?(header)}.first end |
.mime_transform_method(key) ⇒ Object
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.
90 91 92 93 |
# File 'lib/merb-core/controller/mime.rb', line 90 def mime_transform_method(key) raise ArgumentError, ":#{key} is not a valid MIME-type" unless ResponderMixin::TYPES.key?(key) ResponderMixin::TYPES[key][:transform_method] end |
.orm_generator_scope ⇒ Object
344 345 346 347 348 |
# File 'lib/merb-core.rb', line 344 def orm_generator_scope Merb.logger.warn!("WARNING: Merb.orm_generator_scope is deprecated") return :merb_default if Merb.orm == :none Merb.orm end |
.push_path(type, path, file_glob = "**/*.rb") ⇒ Object
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(: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”.
190 191 192 193 |
# File 'lib/merb-core.rb', line 190 def push_path(type, path, file_glob = "**/*.rb") enforce!(type => Symbol) load_paths[type] = [path, file_glob] end |
.rakefiles ⇒ Object
Returns
- Array(String)
-
Paths Rakefiles are loaded from.
Notes
Recommended way to find out what paths Rakefiles are loaded from.
546 547 548 |
# File 'lib/merb-core.rb', line 546 def rakefiles @rakefiles ||= ['merb-core/test/tasks/spectasks'] end |
.reload ⇒ Object
Reload application and framework classes. See Merb::BootLoader::ReloadClasses for details.
463 464 465 |
# File 'lib/merb-core.rb', line 463 def reload Merb::BootLoader::ReloadClasses.reload end |
.remove_mime_type(key) ⇒ Object
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.
77 78 79 80 |
# File 'lib/merb-core/controller/mime.rb', line 77 def remove_mime_type(key) return false if key == :all ResponderMixin::TYPES.delete(key) end |
.remove_paths(*args) ⇒ Object
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(:mailer) Merb.push_path(:mailer, Merb.root / “app” / “models”, “*/.rb”)
Will make Merb use app/models for mailers just like Ruby on Rails does.
212 213 214 |
# File 'lib/merb-core.rb', line 212 def remove_paths(*args) args.each {|arg| load_paths.delete(arg)} end |
.restart_environment(argv = {}) ⇒ Object
Restart the Merb environment explicitly.
Parameters
- argv<String, Hash>
-
The config arguments to restart Merb with. Defaults to
Merb::Config
.
129 130 131 132 |
# File 'lib/merb-core.rb', line 129 def restart_environment(argv={}) @started = false start_environment(Merb::Config.to_hash.merge(argv)) end |
.root ⇒ Object
Returns
- String
-
The Merb root path.
236 237 238 |
# File 'lib/merb-core.rb', line 236 def root @root || Merb::Config[:merb_root] || File.(Dir.pwd) end |
.root=(value) ⇒ Object
Parameters
- value<String>
-
Path to the root directory.
242 243 244 |
# File 'lib/merb-core.rb', line 242 def root=(value) @root = value end |
.root_path(*path) ⇒ Object
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"
260 261 262 |
# File 'lib/merb-core.rb', line 260 def root_path(*path) File.join(root, *path) end |
.start(argv = ARGV) ⇒ Object
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
.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/merb-core.rb', line 94 def start(argv=ARGV) if Hash === argv Merb::Config.setup(argv) else Merb::Config.parse_args(argv) end Merb.environment = Merb::Config[:environment] Merb.root = Merb::Config[:merb_root] case Merb::Config[:action] when :kill Merb::Server.kill(Merb::Config[:port], 1) when :kill_9 Merb::Server.kill(Merb::Config[:port], 9) else Merb::Server.start(Merb::Config[:port], Merb::Config[:cluster]) end end |
.start_environment(argv = ARGV) ⇒ Object
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
.
117 118 119 120 121 122 |
# File 'lib/merb-core.rb', line 117 def start_environment(argv=ARGV) unless (@started ||= false) start(argv) @started = true end end |
.test_framework_generator_scope ⇒ Object
359 360 361 362 |
# File 'lib/merb-core.rb', line 359 def test_framework_generator_scope Merb.logger.warn!("WARNING: Merb.test_framework_generator_scope is deprecated") Merb.test_framework end |