summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-10-20 19:57:02 -0600
committerJason Gerard DeRose <jderose@redhat.com>2008-10-20 19:57:02 -0600
commitc818fe1d2d9ab87c5291ead043784a9d68f95448 (patch)
treeb3aebf6e3cf62c124583f380b9dbfa386a2b9270 /ipalib
parentac0a019605e951e1177d4f721bd4174f3c4b53a3 (diff)
downloadfreeipa-c818fe1d2d9ab87c5291ead043784a9d68f95448.tar.gz
freeipa-c818fe1d2d9ab87c5291ead043784a9d68f95448.tar.xz
freeipa-c818fe1d2d9ab87c5291ead043784a9d68f95448.zip
Added docstring (with examples) to frontend.Method class
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/frontend.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index d70a725e6..dbbb2bc56 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -894,6 +894,68 @@ class Attribute(plugable.Plugin):
class Method(Attribute, Command):
+ """
+ A command with an associated object.
+
+ A `Method` plugin must have a corresponding `Object` plugin. The
+ association between object and method is done through a simple naming
+ convention: the first part of the method name (up to the first under
+ score) is the object name, as the examples in this table show:
+
+ ============= =========== ==============
+ Method name Object name Attribute name
+ ============= =========== ==============
+ user_add user add
+ noun_verb noun verb
+ door_open_now door open_door
+ ============= =========== ==============
+
+ There are three different places a method can be accessed. For example,
+ say you created a `Method` plugin and its corresponding `Object` plugin
+ like this:
+
+ >>> api = plugable.API(Command, Object, Method, Property)
+ >>> class user_add(Method):
+ ... def run(self):
+ ... return 'Added the user!'
+ ...
+ >>> class user(Object):
+ ... pass
+ ...
+ >>> api.register(user_add)
+ >>> api.register(user)
+ >>> api.finalize()
+
+ First, the ``user_add`` plugin can be accessed through the ``api.Method``
+ namespace:
+
+ >>> list(api.Method)
+ ['user_add']
+ >>> api.Method.user_add() # Will call user_add.run()
+ 'Added the user!'
+
+ Second, because `Method` is a subclass of `Command`, the ``user_add``
+ plugin can also be accessed through the ``api.Command`` namespace:
+
+ >>> list(api.Command)
+ ['user_add']
+ >>> api.Command.user_add() # Will call user_add.run()
+ 'Added the user!'
+
+ And third, ``user_add`` can be accessed as an attribute on the ``user``
+ `Object`:
+
+ >>> list(api.Object)
+ ['user']
+ >>> list(api.Object.user.methods)
+ ['add']
+ >>> api.Object.user.methods.add() # Will call user_add.run()
+ 'Added the user!'
+
+ The `Attribute` base class implements the naming convention for the
+ attribute-to-object association. Also see the `Object` and the
+ `Property` classes.
+ """
__public__ = Attribute.__public__.union(Command.__public__)
def __init__(self):