view intentmademanifest/actions.py @ 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
children
line wrap: on
line source

#!/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