Module: Lockdown::Orms::ActiveRecord::Stamps

Defined in:
lib/lockdown/orms/active_record.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/lockdown/orms/active_record.rb', line 40

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

Instance Method Details

#create_with_stampsObject



53
54
55
56
57
58
# File 'lib/lockdown/orms/active_record.rb', line 53

def create_with_stamps
  pid = current_who_did_it || Lockdown::System.fetch(:default_who_did_it)
  self[:created_by] = pid if self.respond_to?(:created_by) 
  self[:updated_by] = pid if self.respond_to?(:updated_by) 
  create_without_stamps
end

#current_who_did_itObject



49
50
51
# File 'lib/lockdown/orms/active_record.rb', line 49

def current_who_did_it
  Thread.current[:who_did_it]
end

#update_with_stampsObject



60
61
62
63
64
# File 'lib/lockdown/orms/active_record.rb', line 60

def update_with_stamps
  pid = current_who_did_it || Lockdown::System.fetch(:default_who_did_it)
  self[:updated_by] = pid if self.respond_to?(:updated_by)
  update_without_stamps
end