Created
September 30, 2009 18:36
-
-
Save sintaxi/198331 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'merb_helpers' | |
base = File.dirname(__FILE__) | |
module ActivityLogging | |
module Model | |
def self.included(base) | |
base.send(:include, InstanceMethods) | |
end | |
module InstanceMethods | |
def after_create | |
if has_assoc? | |
Activity.create(:target => self, :person => self.person, :action_taken => "created", :assoc => self.assoc) | |
else | |
Activity.create(:target => self, :person => self.person, :action_taken => "created") | |
end | |
end | |
def after_update | |
if has_assoc? | |
Activity.create(:target => self, :person => self.person, :action_taken => "updated", :assoc => self.assoc) | |
else | |
Activity.create(:target => self, :person => self.person, :action_taken => "updated") | |
end | |
end | |
def after_delete | |
if has_assoc? | |
Activity.create(:person => self.person, :action_taken => "destroyed #{self.class.to_s}", :assoc => self.assoc) | |
else | |
Activity.create(:person => self.person, :action_taken => "destroyed #{self.class.to_s}") | |
end | |
end | |
def has_assoc? | |
(self.class.to_s == "Post" && self.discussion.discussible.class.to_s == "Assoc") || (self.class.to_s == "Membership" && self.group_type == "Assoc") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment