Skip to content

Commit

Permalink
Merge pull request #290 from Scille/remove_as_attribute
Browse files Browse the repository at this point in the history
Remove as_attribute argument of register method
  • Loading branch information
lafrech committed Jul 20, 2020
2 parents 5aed75f + d3ec99f commit 5636cc4
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions umongo/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,12 @@ def retrieve_embedded_document(self, name_or_template):
'Unknown embedded document class `%s`' % name_or_template)
return self._embedded_lookup[name_or_template]

def register(self, template, as_attribute=True):
def register(self, template):
"""
Generate an :class:`umongo.template.Implementation` from the given
:class:`umongo.template.Template` for this instance.
:param template: :class:`umongo.template.Template` to implement
:param as_attribute:
Make the generated :class:`umongo.template.Implementation` available
as this instance's attribute.
:return: The :class:`umongo.template.Implementation` generated
.. note::
Expand All @@ -105,29 +101,27 @@ class MyDoc(Document):
implementation = self._register_embedded_doc(template)
else: # MixinDocument
implementation = self._register_mixin_doc(template)
if as_attribute:
setattr(self, implementation.__name__, implementation)
return implementation

def _register_doc(self, template):
implementation = self.builder.build_from_template(template)
if hasattr(self, implementation.__name__):
if implementation.__name__ in self._doc_lookup:
raise AlreadyRegisteredDocumentError(
'Document `%s` already registered' % implementation.__name__)
self._doc_lookup[implementation.__name__] = implementation
return implementation

def _register_embedded_doc(self, template):
implementation = self.builder.build_from_template(template)
if hasattr(self, implementation.__name__):
if implementation.__name__ in self._embedded_lookup:
raise AlreadyRegisteredDocumentError(
'EmbeddedDocument `%s` already registered' % implementation.__name__)
self._embedded_lookup[implementation.__name__] = implementation
return implementation

def _register_mixin_doc(self, template):
implementation = self.builder.build_from_template(template)
if hasattr(self, implementation.__name__):
if implementation.__name__ in self._mixin_lookup:
raise AlreadyRegisteredDocumentError(
'MixinDocument `%s` already registered' % implementation.__name__)
self._mixin_lookup[implementation.__name__] = implementation
Expand Down

0 comments on commit 5636cc4

Please sign in to comment.