Hey guys,

i've been trying to port my Logging-Class from liftweb's metamapper to
datamapper.

The idea is:
- having a model called ActionLog
- having hooks in a DM-model (like include MyLogClass::Logged)
- getting every change logged (unlike only updated/created dates)

The model only consists of this:


class ActionLog
        include DataMapper::Resource

        property :id,                   Serial
        property :action,               String, :length => 20, :nullable => 
false
        property :klass,                String, :length => 50, :nullable => 
false
        property :record,               String, :length => 30, :nullable => 
false
        property :time,                 DateTime, :default => Proc.new { |r,p|
Time.now }, :writer => :private

        belongs_to :user

end

module ActionLogging

        module Stamped

                after :create do _log(:create); end
                after :update do _log(:update); end
                after :create do _log(:delete); end

                def _log(action)
                        log = {
                                :action => action,
                                :klass => self.class,
                                :record => self.id,
                                :user => User.current
                        }
                        ActionLog.create(log)

                end
        end

end

In Models which will get stamped i do:
include ActionLogging::Stamped

Is my approach the right way? because it seems i am doing something
wrong. ;)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to