Parent

Namespace

Class Index [+]

Quicksearch

Merb::Config

Attributes

configuration[RW]

:api: private

Public Class Methods

[](key) click to toggle source

Retrieve the value of a config entry.

Parameters

key

The key to retrieve the parameter for.

Returns

Object

The value of the configuration parameter.

:api: public

    # File lib/merb-core/config.rb, line 82
82:       def [](key)
83:         (@configuration ||= setup)[key]
84:       end
[]=(key, val) click to toggle source

Set the value of a config entry.

Parameters

key

The key to set the parameter for.

val

The value of the parameter.

:api: public

    # File lib/merb-core/config.rb, line 93
93:       def []=(key, val)
94:         (@configuration ||= setup)[key] = val
95:       end
configure(&block) click to toggle source

Set configuration parameters from a code block, where each method evaluates to a config parameter.

Parameters

&block

Configuration parameter block.

Examples

  # Set environment and log level.
  Merb::Config.configure do
    environment "development"
    log_level   "debug"
    log_file    Merb.root / "log" / "special.log"
  end

Returns

nil

:api: public

     # File lib/merb-core/config.rb, line 438
438:       def configure(&block)
439:         ConfigBlock.new(self, &block) if block_given?
440:         nil
441:       end
defaults() click to toggle source

Returns the hash of default config values for Merb.

Returns

Hash

The defaults for the config.

:api: private

    # File lib/merb-core/config.rb, line 15
15:       def defaults
16:         @defaults ||= {
17:           :host                   => "0.0.0.0",
18:           :port                   => "4000",
19:           :adapter                => "runner",
20:           :reload_classes         => true,
21:           :fork_for_class_load    => Merb.forking_environment?,
22:           :environment            => "development",
23:           :merb_root              => Dir.pwd,
24:           :use_mutex              => true,
25:           :log_delimiter          => " ~ ",
26:           :log_auto_flush         => false,
27:           :log_level              => :info,
28:           :log_stream             => STDOUT,
29:           :disabled_components    => Merb.on_windows? ? [:signals] : [],
30:           :deferred_actions       => [],
31:           :verbose                => false,
32:           :name                   => "merb",
33:           :kernel_dependencies    => true,
34:           :gemfile                => nil,
35:           :gemenv                 => nil
36:         }
37:       end
delete(key) click to toggle source

Remove the value of a config entry.

Parameters

key

The key of the parameter to delete.

Returns

Object

The value of the removed entry.

:api: public

     # File lib/merb-core/config.rb, line 106
106:       def delete(key)
107:         @configuration.delete(key)
108:       end
fetch(key, default) click to toggle source

Retrieve the value of a config entry, returning the provided default if the key is not present

Parameters

key

The key to retrieve the parameter for.

default

The default value to return if the parameter is not set.

Returns

Object

The value of the configuration parameter or the default.

:api: public

     # File lib/merb-core/config.rb, line 121
121:       def fetch(key, default)
122:         @configuration.fetch(key, default)
123:       end
key?(key) click to toggle source

Detects whether the provided key is in the config.

Parameters

key

The key to check.

Returns

Boolean

True if the key exists in the config.

:api: public

    # File lib/merb-core/config.rb, line 69
69:       def key?(key)
70:         @configuration.key?(key)
71:       end
method_missing(method, *args) click to toggle source

Allows retrieval of single key config values via Merb.config. Allows single key assignment via Merb.config. = …

Parameters

method<~to_s>

Method name as hash key value.

*args

Value to set the configuration parameter to.

Returns

The value of the entry fetched or assigned to.

:api: public

     # File lib/merb-core/config.rb, line 454
454:       def method_missing(method, *args)
455:         if method.to_s[1,1] == '='
456:           @configuration[method.to_s.tr('=','').to_sym] = *args
457:         else
458:           @configuration[method]
459:         end
460:       end
parse_args(argv = ARGV) click to toggle source

Parses the command line arguments and stores them in the config.

Parameters

argv

The command line arguments. Defaults to ARGV.

Returns

The configuration as a hash.

:api: private

     # File lib/merb-core/config.rb, line 191
191:       def parse_args(argv = ARGV)
192:         @configuration ||= {}
193:         # Our primary configuration hash for the length of this method
194:         options = {}
195: 
196:         # Environment variables always win
197:         options[:environment] = ENV["MERB_ENV"] if ENV["MERB_ENV"]
198:         
199:         # Build a parser for the command line arguments
200:         opts = OptionParser.new do |opts|
201:           opts.version = Merb::VERSION
202: 
203:           opts.banner = "Usage: merb [uGdcIpPhmailLerkKX] [argument]"
204:           opts.define_head "Merb. Pocket rocket web framework"
205:           opts.separator '*' * 80
206:           opts.separator "If no flags are given, Merb starts in the "              "foreground on port 4000."
207:           opts.separator '*' * 80
208: 
209:           opts.on("-u", "--user USER", "This flag is for having merb run "                    "as a user other than the one currently logged in. Note: "                    "if you set this you must also provide a --group option "                    "for it to take effect.") do |user|
210:             options[:user] = user
211:           end
212: 
213:           opts.on("-G", "--group GROUP", "This flag is for having merb run "                    "as a group other than the one currently logged in. Note: "                    "if you set this you must also provide a --user option "                    "for it to take effect.") do |group|
214:             options[:group] = group
215:           end
216: 
217:           opts.on("-d", "--daemonize", "This will run a single merb in the "                    "background.") do |daemon|
218:             options[:daemonize] = true
219:           end
220:           
221:           opts.on("-N", "--no-daemonize", "This will allow you to run a "                    "cluster in console mode") do |no_daemon|
222:             options[:daemonize] = false
223:           end
224: 
225:           opts.on("-c", "--cluster-nodes NUM_MERBS", Integer, 
226:                   "Number of merb daemons to run.") do |nodes|
227:             options[:daemonize] = true unless options.key?(:daemonize)
228:             options[:cluster] = nodes
229:           end
230: 
231:           opts.on("-I", "--init-file FILE", "File to use for initialization "                    "on load, defaults to config/init.rb") do |init_file|
232:             options[:init_file] = init_file
233:           end
234: 
235:           opts.on("-p", "--port PORTNUM", Integer, "Port to run merb on, "                    "defaults to 4000.") do |port|
236:             options[:port] = port
237:           end
238: 
239:           opts.on("-o", "--socket-file FILE", "Socket file to run merb on, "                    "defaults to [Merb.root]/log/merb.sock. This is for "                    "web servers, like thin, that use sockets."                    "Specify this *only* if you *must*.") do |port|
240:             options[:socket_file] = port
241:           end
242: 
243:           opts.on("-s", "--socket SOCKNUM", Integer, "Socket number to run "                    "merb on, defaults to 0.") do |port|
244:             options[:socket] = port
245:           end
246: 
247:           opts.on("-n", "--name NAME", String, "Set the name of the application. "                   "This is used in the process title and log file names.") do |name|
248:             options[:name] = name
249:           end
250: 
251:           opts.on("-P", "--pid PIDFILE", "PID file, defaults to "                    "[Merb.root]/log/merb.main.pid for the master process and"                    "[Merb.root]/log/merb.[port number].pid for worker "                    "processes. For clusters, use %s to specify where "                    "in the file merb should place the port number. For "                    "instance: -P myapp.%s.pid") do |pid_file|
252:             options[:pid_file] = pid_file
253:           end
254: 
255:           opts.on("-h", "--host HOSTNAME", "Host to bind to "                    "(default is 0.0.0.0).") do |host|
256:             options[:host] = host
257:           end
258: 
259:           opts.on("-m", "--merb-root /path/to/approot", "The path to the "                    "Merb.root for the app you want to run "                    "(default is current working directory).") do |root|
260:             options[:merb_root] = File.expand_path(root)
261:           end
262: 
263:           adapters = [:mongrel, :emongrel, :thin, :ebb, :fastcgi, :webrick]
264: 
265:           opts.on("-a", "--adapter ADAPTER",
266:                   "The rack adapter to use to run merb (default is thin)"                    "[#{adapters.join(', ')}]") do |adapter|
267:             options[:adapter] ||= adapter
268:           end
269: 
270:           opts.on("-R", "--rackup FILE", "Load an alternate Rack config "                    "file (default is config/rack.rb)") do |rackup|
271:             options[:rackup] = rackup
272:           end
273: 
274:           opts.on("-i", "--irb-console", "This flag will start merb in "                    "irb console mode. All your models and other classes will "                    "be available for you in an irb session.") do |console|
275:             options[:adapter] = 'irb'
276:           end
277: 
278:           opts.on("-S", "--sandbox", "This flag will enable a sandboxed irb "                    "console. If your ORM supports transactions, all edits will "                    "be rolled back on exit.") do |sandbox|
279:             options[:sandbox] = true
280:           end
281: 
282:           opts.on("-l", "--log-level LEVEL", "Log levels can be set to any of "                    "these options: debug < info < warn < error < "                    "fatal (default is info)") do |log_level|
283:             options[:log_level] = log_level.to_sym
284:             options[:force_logging] = true
285:           end
286: 
287:           opts.on("-L", "--log LOGFILE", "A string representing the logfile to "                    "use. Defaults to [Merb.root]/log/merb.[main].log for the "                    "master process and [Merb.root]/log/merb[port number].log"                    "for worker processes") do |log_file|
288:             options[:log_file] = log_file
289:             options[:force_logging] = true
290:           end
291: 
292:           opts.on("-e", "--environment STRING", "Environment to run Merb "                    "under [development, production, testing] "                    "(default is development)") do |env|
293:             options[:environment] = env
294:           end
295: 
296:           opts.on("-r", "--script-runner ['RUBY CODE'| FULL_SCRIPT_PATH]",
297:                   "Command-line option to run scripts and/or code in the "                    "merb app.") do |code_or_file|
298:             options[:runner_code] = code_or_file
299:             options[:adapter] = 'runner'
300:           end
301: 
302:           opts.on("-K", "--graceful PORT or all", "Gracefully kill one "                    "merb proceses by port number.  Use merb -K all to "                    "gracefully kill all merbs.") do |ports|
303:             options[:action] = :kill
304:             ports = "main" if ports == "all"
305:             options[:port] = ports
306:           end
307: 
308:           opts.on("-k", "--kill PORT", "Force kill one merb worker "                    "by port number. This will cause the worker to"                    "be respawned.") do |port|
309:             options[:action] = :kill_9
310:             port = "main" if port == "all"
311:             options[:port] = port
312:           end
313:           
314:           opts.on("--fast-deploy", "Reload the code, but not your"              "init.rb or gems") do
315:               options[:action] = :fast_deploy
316:           end
317: 
318:           # @todo Do we really need this flag? It seems unlikely to want to
319:           #   change the mutex from the command-line.
320:           opts.on("-X", "--mutex on/off", "This flag is for turning the "                    "mutex lock on and off.") do |mutex|
321:             if mutex == "off"
322:               options[:use_mutex] = false
323:             else
324:               options[:use_mutex] = true
325:             end
326:           end
327: 
328:           opts.on("-D", "--debugger", "Run merb using rDebug.") do
329:             begin
330:               require "ruby-debug"
331:               Debugger.start
332: 
333:               # Load up any .rdebugrc files we find
334:               [".", ENV["HOME"], ENV["HOMEPATH"]].each do |script_dir|
335:                 script_file = "#{script_dir}/.rdebugrc"
336:                 Debugger.run_script script_file, StringIO.new if File.exists?(script_file)
337:               end
338: 
339:               if Debugger.respond_to?(:settings)
340:                 Debugger.settings[:autoeval] = true
341:               end
342:               puts "Debugger enabled"
343:             rescue LoadError
344:               puts "You need to install ruby-debug to run the server in "                  "debugging mode. With gems, use `gem install ruby-debug'"
345:               exit
346:             end
347:           end
348: 
349:           opts.on("-V", "--verbose", "Print extra information") do
350:             options[:verbose] = true
351:           end
352: 
353:           opts.on("-C", "--console-trap", "Enter an irb console on ^C") do
354:             options[:console_trap] = true
355:           end
356: 
357:           opts.on("-?", "-H", "--help", "Show this help message") do
358:             puts opts
359:             exit
360:           end
361:         end
362: 
363:         # Parse what we have on the command line
364:         begin
365:           opts.parse!(argv)
366:         rescue OptionParser::InvalidOption => e
367:           Merb.fatal! e.message, e
368:         end
369:         Merb::Config.setup(options)
370:       end
session_stores() click to toggle source

Returns stores list constructed from configured session stores (:session_stores config option) or default one (:session_store config option).

:api: private

    # File lib/merb-core/dispatch/session.rb, line 17
17:     def self.session_stores
18:       @session_stores ||= begin
19:         config_stores = Array(
20:           Merb::Config[:session_stores] || Merb::Config[:session_store]
21:         )
22:         config_stores.map { |name| name.to_sym }
23:       end
24:     end
setup(settings = {}) click to toggle source

Sets up the configuration by storing the given settings.

Parameters

settings

Configuration settings to use. These are merged with the defaults.

Returns

The configuration as a hash.

:api: private

     # File lib/merb-core/config.rb, line 156
156:       def setup(settings = {})
157:         # Merge new settings with any existing configuration settings
158:         settings = @configuration.merge(settings) unless @configuration.nil?
159:         
160:         # Merge new settings with default settings
161:         config = defaults.merge(settings)
162:         
163:         unless config[:reload_classes]
164:           config[:fork_for_class_load] = false
165:         end
166: 
167:         dev_mode = config[:environment] == "development"
168:         unless config.key?(:reap_workers_quickly)
169:           config[:reap_workers_quickly] = dev_mode & !config[:cluster]
170:         end
171:         
172:         unless config.key?(:bind_fail_fatal)
173:           config[:bind_fail_fatal] = dev_mode
174:         end
175:         
176:         # Set mutex to dispatcher
177:         ::Merb::Dispatcher.use_mutex = config[:use_mutex]
178: 
179:         @configuration = config
180:       end
to_hash() click to toggle source

Returns the configuration as a hash.

Returns

Hash

The config as a hash.

:api: public

     # File lib/merb-core/config.rb, line 131
131:       def to_hash
132:         @configuration
133:       end
to_yaml() click to toggle source

Returns the config as YAML.

Returns

String

The config as YAML.

:api: public

     # File lib/merb-core/config.rb, line 141
141:       def to_yaml
142:         require "yaml"
143:         @configuration.to_yaml
144:       end
use() click to toggle source

Yields the configuration.

Block parameters

c

The configuration parameters.

Examples

  Merb::Config.use do |config|
    config[:exception_details] = false
    config[:log_stream]        = STDOUT
  end

Returns

nil

:api: public

    # File lib/merb-core/config.rb, line 54
54:       def use
55:         @configuration ||= {}
56:         yield @configuration
57:         nil
58:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.