Module: Strelka
- Extended by:
- Loggability, MethodUtilities
- Includes:
- Constants
- Defined in:
- lib/strelka.rb,
lib/strelka/mixins.rb,
lib/strelka/plugins.rb,
lib/strelka/exceptions.rb
Overview
--
Defined Under Namespace
Modules: AbstractClass, CLI, Constants, DataUtilities, Delegation, Discovery, MethodUtilities, Plugin, PluginLoader, ResponseHelpers, SignalHandling, Testing Classes: App, AuthProvider, Cookie, CookieError, CookieSet, Error, HTTPRequest, HTTPResponse, MultiRunner, MultipartParser, ParamValidator, ParseError, PluginError, PluginRegistry, RequestError, Router, Session, WebSocketServer
Constant Summary collapse
- VERSION =
Library version constant
'0.19.3'- REVISION =
Version-control revision constant
%q$Revision$- CONFIG_ENV =
The name of the environment variable that can be used to specify a configfile to load.
'STRELKA_CONFIG'- LOCAL_CONFIG_FILE =
The name of the config file for local overrides.
Pathname( '~/.strelka.yml' ).
- DEFAULT_CONFIG_FILE =
The name of the config file that's loaded if none is specified.
Pathname( 'config.yml' ).
Class Method Summary collapse
-
.after_configure(&block) ⇒ Object
Register a callback to be run after the config is loaded.
-
.App(appname) ⇒ Object
Look up the application class of
appname, optionally limiting it to the gem namedgemname. -
.before_fork(&block) ⇒ Object
Register a callback to be run before forking a Strelka::Handler subprocess.
-
.call_after_configure_hooks ⇒ Object
Call the post-configuration callbacks.
-
.call_before_fork_hooks ⇒ Object
Call the before-fork hooks.
-
.config ⇒ Object
Get the loaded config (a Configurability::Config object).
-
.config_loaded? ⇒ Boolean
Returns
trueif the configuration has been loaded at least once. -
.load_config(config_file = nil, defaults = nil) ⇒ Object
Load the specified
config_file, install the config in all objects with Configurability, and call any callbacks registered via #after_configure. -
.version_string(include_buildnum = false) ⇒ Object
Get the library version.
Instance Method Summary collapse
-
#after_configure_hooks ⇒ Object
An Array of callbacks to be run after the config is loaded.
-
#after_configure_hooks_run ⇒ Object
True if the after_configure hooks have already (started to) run.
-
#before_fork_hooks ⇒ Object
An Array of callbacks to be run before forking a handler process.
Methods included from MethodUtilities
attr_predicate, attr_predicate_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias, singleton_predicate_accessor, singleton_predicate_reader
Class Method Details
.after_configure(&block) ⇒ Object
Register a callback to be run after the config is loaded.
108 109 110 111 112 113 114 115 |
# File 'lib/strelka.rb', line 108 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 |
.App(appname) ⇒ Object
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.
171 172 173 |
# File 'lib/strelka.rb', line 171 def self::App( appname ) return Strelka::Discovery.load( appname ) end |
.before_fork(&block) ⇒ Object
Register a callback to be run before forking a Strelka::Handler subprocess.
144 145 146 147 |
# File 'lib/strelka.rb', line 144 def self::before_fork( &block ) raise LocalJumpError, "no block given" unless block self.before_fork_hooks << block end |
.call_after_configure_hooks ⇒ Object
Call the post-configuration callbacks.
120 121 122 123 124 125 126 127 128 |
# File 'lib/strelka.rb', line 120 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_before_fork_hooks ⇒ Object
Call the before-fork hooks.
132 133 134 135 136 137 138 139 |
# File 'lib/strelka.rb', line 132 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 |
.config ⇒ Object
Get the loaded config (a Configurability::Config object)
96 97 98 |
# File 'lib/strelka.rb', line 96 def self::config Configurability.loaded_config end |
.config_loaded? ⇒ Boolean
Returns true if the configuration has been loaded at least once.
102 103 104 |
# File 'lib/strelka.rb', line 102 def self::config_loaded? return self.config ? true : false end |
.load_config(config_file = nil, defaults = nil) ⇒ Object
Load the specified config_file, install the config in all objects with
Configurability, and call any callbacks registered via #after_configure.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/strelka.rb', line 152 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 |
.version_string(include_buildnum = false) ⇒ Object
Get the library version. If include_buildnum is true, the version string will
include the VCS rev ID.
59 60 61 62 63 |
# File 'lib/strelka.rb', line 59 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 |
Instance Method Details
#after_configure_hooks ⇒ Object
An Array of callbacks to be run after the config is loaded
77 |
# File 'lib/strelka.rb', line 77 singleton_attr_reader :after_configure_hooks |
#after_configure_hooks_run ⇒ Object
True if the after_configure hooks have already (started to) run.
87 |
# File 'lib/strelka.rb', line 87 singleton_predicate_reader :after_configure_hooks_run |
#before_fork_hooks ⇒ Object
An Array of callbacks to be run before forking a handler process
82 |
# File 'lib/strelka.rb', line 82 singleton_attr_reader :before_fork_hooks |