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



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

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



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

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

#current_who_did_itObject



47
48
49
# File 'lib/lockdown/orms/active_record.rb', line 47

def current_who_did_it
  Thread.current[:who_did_it]
end

#update_with_stampsObject



58
59
60
61
62
# File 'lib/lockdown/orms/active_record.rb', line 58

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