Skip to content

Instantly share code, notes, and snippets.

@sintaxi
Created September 30, 2009 18:36
Show Gist options
  • Save sintaxi/198331 to your computer and use it in GitHub Desktop.
Save sintaxi/198331 to your computer and use it in GitHub Desktop.
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