lib/plugins/pluginmanager.rb in rsence-pre-2.1.0.1.pre vs lib/plugins/pluginmanager.rb in rsence-pre-2.1.0.2.pre

- old
+ new

@@ -23,11 +23,17 @@ attr_reader :transporter, :sessions # Returns the registry data for plugin bundle +plugin_name+ def registry( plugin_name ) - return @registry[ plugin_name ] + if @registry.has_key?( plugin_name ) + return @registry[ plugin_name ] + elsif @parent_manager + return @parent_manager.registry( plugin_name ) + else + throw "Plugin not in registry: #{plugin_name.inspect}" + end end alias [] registry # By default, calling a method not defined calls a plugin of that name def method_missing( sym, *args, &block ) @@ -35,10 +41,12 @@ if args == [] and block == nil return @registry[sym] elsif block == nil call( sym, *args ) end + elsif @parent_manager + return @parent_manager.method_missing( sym, *args, &block ) end end # Registers alias name for a plugin bundle. def register_alias( bundle_name, alias_name ) @@ -582,24 +590,33 @@ update_bundles! end # Initialize with a list of directories as plugin_paths. # It's an array containing all plugin directories to scan. - def initialize( plugin_paths, transporter=nil, - autoreload=false, name_prefix=false, - resolved_deps=[], resolved_categories={} ) - if transporter - @transporter = transporter - @sessions = transporter.sessions - end - @name_prefix = name_prefix - @plugin_paths = plugin_paths - @deps = Dependencies.new( resolved_deps, resolved_categories ) - puts "Loading #{name_prefix+' ' if name_prefix}plugins..." if RSence.args[:verbose] + def initialize( options ) + options = { + :plugin_paths => nil, + :transporter => nil, + :autoreload => false, + :name_prefix => false, + :resolved_deps => [], + :resolved_categories => {}, + :parent_manager => nil + }.merge( options ) + + self.plugin_paths = options[:plugin_paths] + self.transporter = options[:transporter] + self.autoreload = options[:autoreload] + self.name_prefix = options[:name_prefix] + self.parent_manager = options[:parent_manager] + + @deps = Dependencies.new( options[:resolved_deps], options[:resolved_categories] ) + + puts "Loading #{@name_prefix+' ' if @name_prefix}plugins..." if RSence.args[:verbose] init_bundles! - puts %{Plugins #{"of #{name_prefix} " if name_prefix}loaded.} if RSence.args[:verbose] - if autoreload + puts %{Plugins #{"of #{@name_prefix} " if @name_prefix}loaded.} if RSence.args[:verbose] + if @autoreload @thr = Thread.new do Thread.pass while true begin update_bundles! @@ -608,10 +625,42 @@ end sleep 3 end end end + end + + attr_reader :transporter + attr_reader :sessions + def transporter=( transporter ) + if transporter + @transporter = transporter + @sessions = transporter.sessions + end + end + + attr_reader :autoreload + def autoreload=( autoreload ) + @autoreload = autoreload + end + + attr_reader :name_prefix + def name_prefix=( name_prefix ) + @name_prefix = name_prefix + end + + attr_reader :plugin_paths + def plugin_paths=( plugin_paths ) + @plugin_paths = plugin_paths + end + + # Optionally set a parent plugin manager to fall back on + attr_reader :parent_manager + def parent_manager=( parent_manager ) + @parent_manager = parent_manager + end + end end