Sha256: 2a05de652969d37948e25f4e88c53860bf82a74e35a8b1eaaae0358fa2913394

Contents?: true

Size: 1.1 KB

Versions: 28

Compression:

Stored size: 1.1 KB

Contents

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_method :create_without_stamps,  :create
          alias_method :create,  :create_with_stamps
          alias_method :update_without_stamps,  :update
          alias_method :update,  :update_with_stamps
        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
                  
      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
    end # InstanceMethods
  end # Model
end # Lockdown

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

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
lockdown-0.4.4 lib/lockdown/model.rb
lockdown-0.4.2 lib/lockdown/model.rb
lockdown-0.4.1 lib/lockdown/model.rb
lockdown-0.4.3 lib/lockdown/model.rb
lockdown-0.5.0 lib/lockdown/model.rb
lockdown-0.5.1 lib/lockdown/model.rb
lockdown-0.5.10 lib/lockdown/model.rb
lockdown-0.5.11 lib/lockdown/model.rb
lockdown-0.5.12 lib/lockdown/model.rb
lockdown-0.5.13 lib/lockdown/model.rb
lockdown-0.5.14 lib/lockdown/model.rb
lockdown-0.4.5 lib/lockdown/model.rb
lockdown-0.5.16 lib/lockdown/model.rb
lockdown-0.4.6 lib/lockdown/model.rb
lockdown-0.5.17 lib/lockdown/model.rb
lockdown-0.5.18 lib/lockdown/model.rb
lockdown-0.5.9 lib/lockdown/model.rb
lockdown-0.5.19 lib/lockdown/model.rb
lockdown-0.5.2 lib/lockdown/model.rb
lockdown-0.5.20 lib/lockdown/model.rb