module Strelka

A Ruby application framework for Mongrel2.

Author/s

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

version_string( include_buildnum=false ) click to toggle source

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

after_configure_hooks() click to toggle source

An Array of callbacks to be run after the config is loaded

# File lib/strelka.rb, line 76
singleton_attr_reader :after_configure_hooks
after_configure_hooks_run() click to toggle source

True if the after_configure hooks have already (started to) run.

# File lib/strelka.rb, line 86
singleton_predicate_reader :after_configure_hooks_run
before_fork_hooks() click to toggle source

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

↑ top

Public Class Methods

App( appname ) click to toggle source

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
after_configure( &block ) click to toggle source

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
before_fork( &block ) click to toggle source

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_after_configure_hooks() click to toggle source

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_before_fork_hooks() click to toggle source

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
config() click to toggle source

Get the loaded config (a Configurability::Config object)

# File lib/strelka.rb, line 95
def self::config
        Configurability.loaded_config
end
config_loaded?() click to toggle source

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_config( config_file=nil, defaults=nil ) click to toggle source

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