module Strelka
A Ruby application framework for Mongrel2.
Author/s¶ ↑
-
Michael Granger <ged@FaerieMUD.org>
-
Mahlon E. Smith <mahlon@martini.nu>
Constants
- CONFIG_ENV
The name of the environment variable that can be used to specify a configfile to load.
- DEFAULT_CONFIG_FILE
The name of the config file that's loaded if none is specified.
- LOCAL_CONFIG_FILE
The name of the config file for local overrides.
- REVISION
Version-control revision constant
- VERSION
Library version constant
Public Class Methods
Get the library version. If include_buildnum
is true, the version string will include the VCS rev ID.
# File lib/strelka.rb, line 58 def self::version_string( include_buildnum=false ) vstring = "%s %s" % [ self.name, VERSION ] vstring << " (build %s)" % [ REVISION[/: ([[:xdigit:]]+)/, 1] || '0' ] if include_buildnum return vstring end
Public Instance Methods
An Array of callbacks to be run after the config is loaded
# File lib/strelka.rb, line 76 singleton_attr_reader :after_configure_hooks
True if the after_configure
hooks have already (started to) run.
# File lib/strelka.rb, line 86 singleton_predicate_reader :after_configure_hooks_run
An Array of callbacks to be run before forking a handler process
# File lib/strelka.rb, line 81 singleton_attr_reader :before_fork_hooks
Configuration API
↑ topPublic Class Methods
Look up the application class of appname
, optionally limiting it to the gem named gemname
. Returns the first matching class, or raises an exception if no app class was found.
# File lib/strelka.rb, line 170 def self::App( appname ) return Strelka::Discovery.load( appname ) end
Register a callback to be run after the config is loaded.
# File lib/strelka.rb, line 107 def self::after_configure( &block ) raise LocalJumpError, "no block given" unless block self.after_configure_hooks << block # Call the block immediately if the hooks have already been called or are in # the process of being called. block.call if self.after_configure_hooks_run? end
Register a callback to be run before forking a Strelka::Handler subprocess.
# File lib/strelka.rb, line 143 def self::before_fork( &block ) raise LocalJumpError, "no block given" unless block self.before_fork_hooks << block end
Call the post-configuration callbacks.
# File lib/strelka.rb, line 119 def self::call_after_configure_hooks self.log.debug " calling %d post-config hooks" % [ self.after_configure_hooks.length ] @after_configure_hooks_run = true self.after_configure_hooks.to_a.each do |hook| self.log.debug " %s line %s..." % hook.source_location hook.call end end
Call the before-fork hooks.
# File lib/strelka.rb, line 131 def self::call_before_fork_hooks self.log.debug " calling %d before-fork hooks" % [ self.before_fork_hooks.length ] self.before_fork_hooks.to_a.each do |hook| self.log.debug " %s line %s..." % hook.source_location hook.call end end
Get the loaded config (a Configurability::Config object)
# File lib/strelka.rb, line 95 def self::config Configurability.loaded_config end
Returns true
if the configuration has been loaded at least once.
# File lib/strelka.rb, line 101 def self::config_loaded? return self.config ? true : false end
Load the specified config_file
, install the config in all objects with Configurability, and call any callbacks registered via after_configure.
# File lib/strelka.rb, line 151 def self::load_config( config_file=nil, defaults=nil ) config_file ||= ENV[ CONFIG_ENV ] config_file ||= LOCAL_CONFIG_FILE if LOCAL_CONFIG_FILE.exist? config_file ||= DEFAULT_CONFIG_FILE defaults ||= Configurability.gather_defaults self.log.warn "Loading config from %p with defaults for sections: %p." % [ config_file, defaults.keys ] config = Configurability::Config.load( config_file, defaults ) config.install self.call_after_configure_hooks end