Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Docstings on manager helper methods.

  • Loading branch information...
commit 85c292b4dd069ce68e35b12d58f67b4861f43bea 1 parent dc69b89
@ironfroggy authored
Showing with 17 additions and 0 deletions.
  1. +17 −0 straight/plugin/manager.py
View
17 straight/plugin/manager.py
@@ -24,6 +24,10 @@ 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)
@@ -31,6 +35,8 @@ def produce(self, *args, **kwargs):
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:
@@ -38,6 +44,10 @@ def call(self, method, *args, **kwargs):
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
@@ -45,6 +55,13 @@ def first(self, method, *args, **kwargs):
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:
Please sign in to comment.
Something went wrong with that request. Please try again.