module Strelka::Plugin
Plugin
Module extension – adds registration, load-order support, etc.
Attributes
pluggable[RW]
The Class/Module that this plugin belongs to
successors[RW]
An Array that tracks which plugins should be installed after itself.
Public Class Methods
extended( object )
click to toggle source
Extension hook – Extend the given object with methods for setting it up as a plugin for its containing namespace.
Calls superclass method
# File lib/strelka/plugins.rb, line 39 def self::extended( object ) super object.extend( Loggability ) object.log_to( :strelka ) # Find the plugin's namespace container, which will be the # pluggable class/module pluggable_name = object.name.split( '::' )[ 0..-2 ] pluggable = pluggable_name.inject( Object ) do |mod, name| mod.const_get( name ) end self.log.debug "Extending %p as a Strelka::Plugin for %p" % [ object, pluggable ] object.successors = Set.new object.pluggable = pluggable # Register any pending dependencies for the newly-loaded plugin name = object.plugin_name if (( deps = pluggable.loaded_plugins[name] )) self.log.debug " installing deferred deps for %p" % [ name ] object.run_inside( *deps ) end self.log.debug " adding %p (%p) to the plugin registry for %p" % [ name, object, pluggable ] pluggable.loaded_plugins[ name ] = object end
Public Instance Methods
plugin_name()
click to toggle source
Return the name of the receiving plugin
# File lib/strelka/plugins.rb, line 80 def plugin_name name = self.name || "anonymous#{self.object_id}" name = name.sub( /.*::/, '' ) return name.downcase.to_sym end
run_inside( *other_plugins )
click to toggle source
Register the receiver as needing to be run after other_plugins
for requests, and before them for responses.
# File lib/strelka/plugins.rb, line 108 def run_inside( *other_plugins ) self.log.debug " %p will run after %p" % [ self, other_plugins ] self.successors.merge( other_plugins ) end
Also aliased as: run_after
run_outside( *other_plugins )
click to toggle source
Register the receiver as needing to be run before other_plugins
for requests, and after them for responses.
# File lib/strelka/plugins.rb, line 89 def run_outside( *other_plugins ) name = self.plugin_name other_plugins.each do |other_name| self.pluggable.loaded_plugins[ other_name ] ||= [] mod = self.pluggable.loaded_plugins[ other_name ] if mod.respond_to?( :run_inside ) mod.run_inside( name ) else self.log.debug "%p plugin not yet loaded; setting up pending deps" % [ other_name ] mod << name end end end
Also aliased as: run_before