Sha256: dd246fc80293e8edda51cc8d8720237934d0074da59e8a360767684a34a42ccc

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

require File.join(File.dirname(__FILE__), "helper") unless Lockdown.const_defined?("Helper")

module Lockdown
  module Model
    def self.included(base)
      base.send :include, Lockdown::Model::InstanceMethods
    end

    module InstanceMethods
      def self.included(base)
        base.class_eval do
          alias :create_without_stamps  :create
          alias :update_without_stamps  :update
        end
      end

      def current_profile_id
        Thread.current[:profile_id]
      end


      def create_with_stamps
        profile_id = current_profile_id || Profile::SYSTEM
        self[:created_by] = profile_id if self.respond_to?(:created_by) 
        self[:updated_by] = profile_id if self.respond_to?(:updated_by) 
        create_without_stamps
      end
      alias :create  :create_with_stamps
                  
      def update_with_stamps
        profile_id = current_profile_id || Profile::SYSTEM
        self[:updated_by] = profile_id if self.respond_to?(:updated_by)
        update_without_stamps
      end
      alias :update  :update_with_stamps
    end # InstanceMethods
  end # Model
end # Lockdown

Lockdown.orm_parent.send :include, Lockdown::Model

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lockdown-0.1.0 lib/lockdown/model.rb
lockdown-0.1.1 lib/lockdown/model.rb
lockdown-0.1.2 lib/lockdown/model.rb
lockdown-0.1.3 lib/lockdown/model.rb
lockdown-0.1.4 lib/lockdown/model.rb
lockdown-0.2.0 lib/lockdown/model.rb