changeset 15:c7585bd93680

stub for actions module for python function dep unrolling
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 08 Jun 2013 07:12:15 -0700
parents 6715102c5a86
children 4353d36a2f80
files intentmademanifest/actions.py
diffstat 1 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
new file mode 100755
--- /dev/null
+++ b/intentmademanifest/actions.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+
+"""
+``intentmademanifest.actions`` is a dependency resolver for python instance
+methods
+"""
+
+# TODO: generalize, if possible.  For instance, we don't care about
+# parameter space; should we? how?
+
+class Actions(object):
+
+    @classmethod
+    def requires(cls, method, *requirements):
+        """
+        Require all dependencies to be run before invoking the method.
+        - requirements: method names
+        """
+        # TODO: as is, the intent is to run all of the requirements
+        # and then invoke ``method``
+        # alternatively, e.g. via subclass, one could err out if the 
+        # requirements have not been run
+
+class ActionsCLI(object):
+    """command line handler for an actions-based class"""
+    def __init__(self):
+        raise NotImplementedError("TODO")
+
+requires = Actions.requires
+
+if __name__ == '__main__':
+    # TODO: -> test
+
+    class ActionsExample(object):
+        """example class for illustration of ``intentmademanifest.actions``"""
+
+        def foo(self):
+            self.attr = 1
+
+        @requires('foo')
+        def bar(self):
+            self.attr *= 2
+
+        def fleem(self):
+            self.another_attr = 3
+
+        @requires('bar', 'fleem')
+        def result(self):
+            return self.attr * self.another_attr
+
+    instance = ActionsExample()
+    assert instance.result() == 6