summaryrefslogtreecommitdiff
path: root/users/app
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-11-06 11:26:46 +0100
committerAzul <azul@leap.se>2013-11-06 11:30:33 +0100
commit24598b5c5e4df20c423ec74ea8e9df1592483c6b (patch)
tree08697724628ae443599c3c745c11757e75b40d12 /users/app
parentebc60f3aba1ca08e454ba5e91f49905df2e5fa13 (diff)
destroy all tickets created by a user when account is destroyed
In order to keep the users engine independent of the tickets engine i added a generic load hook to the account model. The tickets engine then monkeypatches the account destruction and destroys all tickets before the user is destroyed. The tickets are destroyed first so that even if things break there should never be tickets with an outdated user id. I would have prefered to use super over using an alias_method_chain but I have not been able to figure out a way to make account a superclass of the account extension and still refer to Account from the users engine.
Diffstat (limited to 'users/app')
-rw-r--r--users/app/models/account.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/users/app/models/account.rb b/users/app/models/account.rb
index 726f642..5c943bb 100644
--- a/users/app/models/account.rb
+++ b/users/app/models/account.rb
@@ -1,5 +1,10 @@
#
-# A Composition of a User record and it's identity records.
+# The Account model takes care of the livecycle of a user.
+# It composes a User record and it's identity records.
+# It also allows for other engines to hook into the livecycle by
+# monkeypatching the create, update and destroy methods.
+# There's an ActiveSupport load_hook at the end of this file to
+# make this more easy.
#
class Account
@@ -52,4 +57,7 @@ class Account
@new_identity.try(:save) && @old_identity.try(:save)
end
+ # You can hook into the account lifecycle from different engines using
+ # ActiveSupport.on_load(:account) do ...
+ ActiveSupport.run_load_hooks(:account, self)
end