Plugin Module extension – adds registration, load-order support, etc.
The Class/Module that this plugin belongs to
An Array that tracks which plugins should be installed after itself.
Extension hook – Extend the given object with methods for setting it up as a plugin for its containing namespace.
# 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
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.sub!( /.*::/, '' )
return name.downcase.to_sym
end
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
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