lib/plugins/pluginmanager.rb in rsence-pre-2.1.0.6.pre vs lib/plugins/pluginmanager.rb in rsence-pre-2.1.0.7.pre

- old
+ new

@@ -22,11 +22,12 @@ class PluginManager attr_reader :transporter, :sessions # Returns the registry data for plugin bundle +plugin_name+ - def registry( plugin_name ) + def registry( plugin_name=false ) + return @registry unless plugin_name if @registry.has_key?( plugin_name ) return @registry[ plugin_name ] elsif @parent_manager return @parent_manager.registry( plugin_name ) else @@ -69,15 +70,31 @@ end else inst.init if inst.respond_to? :init and not inst.inited @registry[ bundle_name ] = inst if inst.respond_to?( :match ) and ( inst.respond_to?( :get ) or inst.respond_to?( :post ) ) - @servlets.push( bundle_name ) + add_servlet( bundle_name ) end end end + def add_servlet( bundle_name ) + if @parent_manager + sub_name = "#{@name_prefix.to_s}:#{bundle_name.to_s}" + @parent_manager.add_servlet( sub_name ) + end + @servlets.push( bundle_name ) + end + + def del_servlet( bundle_name ) + if @parent_manager + sub_name = "#{@name_prefix.to_s}:#{bundle_name.to_s}" + @parent_manager.del_servlet( sub_name ) + end + @servlets.delete( bundle_name ) + end + def callable?( plugin_name, method_name ) return false if @deps.category?( plugin_name ) return false unless @registry.has_key?( plugin_name ) plugin = @registry[plugin_name] return false unless plugin.respond_to?( method_name ) @@ -85,10 +102,11 @@ end # Calls the method +method_name+ with args +args+ of the plugin +plugin_name+. # Returns false, if no such plugin or method exists. def call( plugin_name, method_name, *args ) + puts "#{plugin_name}.#{method_name}" if RSence.args[:trace_delegate] plugin_name_s = plugin_name.to_s if plugin_name_s.include?(':') colon_index = plugin_name_s.index(':') sub_manager_name = plugin_name_s[0..(colon_index-1)].to_sym plugin_name = plugin_name_s[(colon_index+1)..-1].to_sym @@ -145,25 +163,14 @@ # Search servlets that match the +uri+ and +req_type+ def match_servlet_uri( uri, req_type=:get ) match_score = {} @servlets.each do | servlet_name | - servlet = @registry[ servlet_name ] - next unless servlet.respond_to?( req_type ) - begin - if servlet.match( uri, req_type ) - score = servlet.score - match_score[ score ] = [] unless match_score.has_key? score - match_score[ score ].push( servlet_name ) - end - rescue => e - plugin_error( - e, - "RSence::PluginManager.match_servlet_uri", - "servlet: #{servlet_name.inspect}, req_type: #{req_type.inspect}, uri: #{uri.inspect}", - servlet_name - ) + if call( servlet_name, :match, uri, req_type ) + score = call( servlet_name, :score ) + match_score[ score ] = [] unless match_score.has_key? score + match_score[ score ].push( servlet_name ) end end match_scores = match_score.keys.sort if match_scores.empty? return false @@ -191,11 +198,11 @@ req_uri = req.fullpath matches_order = match_servlet_uri( req_uri, req_type ) return false unless matches_order matches_order.each do |servlet_name| begin - @registry[servlet_name].send( req_type, req, resp, session ) + call( servlet_name, req_type, req, resp, session ) return true rescue => e plugin_error( e, "RSence::PluginManager.match_servlet", @@ -481,11 +488,11 @@ if b_name == bundle_name @aliases.delete( a_name ) end end if @servlets.include?( bundle_name ) - @servlets.delete( bundle_name ) + del_servlet( bundle_name ) end if @info.include?( bundle_name ) @info.delete( bundle_name ) end @transporter.online = online_status if @transporter @@ -618,14 +625,14 @@ attr_reader :autoreload attr_reader :name_prefix attr_reader :plugin_paths attr_reader :parent_manager - @@pluginmanager_id = 0 # Initialize with a list of directories as plugin_paths. # It's an array containing all plugin directories to scan. def initialize( options ) + options = { :plugin_paths => nil, :transporter => nil, :autoreload => false, :name_prefix => false,