Browse files

Docstings on manager helper methods.

  • Loading branch information...
1 parent dc69b89 commit 85c292b4dd069ce68e35b12d58f67b4861f43bea @ironfroggy committed Jul 1, 2012
Showing with 17 additions and 0 deletions.
  1. +17 −0 straight/plugin/manager.py
View
17 straight/plugin/manager.py
@@ -24,27 +24,44 @@ def __getitem__(self, index):
return self._plugins[index]
def produce(self, *args, **kwargs):
+ """Produce a new set of plugins, treating the current set as plugin
+ factories.
+ """
+
new_plugin_set = PluginManager()
for p in self._plugins:
r = p(*args, **kwargs)
new_plugin_set._plugins.append(r)
return new_plugin_set
def call(self, method, *args, **kwargs):
+ """Call a common method on all the plugins, if it exists."""
+
for plugin in self._plugins:
method = getattr(plugin, method, None)
if method is None:
continue
yield method(*args, **kwargs)
def first(self, method, *args, **kwargs):
+ """Call a common method on all the plugins, if it exists. Return the
+ first result (the first non-None)
+ """
+
for r in self.call(method, *args, **kwargs):
if r is not None:
return r
raise ValueError("No plugins returned a non-None value")
def pipe(self, methodname, first_arg, *args, **kwargs):
+ """Call a common method on all the plugins, if it exists. The return
+ value of each call becomes the replaces the first argument in the given
+ argument list to pass to the next.
+
+ Useful to utilize plugins as sets of filters.
+ """
+
for plugin in self._plugins:
method = getattr(plugin, methodname, None)
if method is None:

0 comments on commit 85c292b

Please sign in to comment.