Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/audit_trails/ar_enhanced.rb
Direct Known Subclasses
Instance Method Summary collapse
- #current_user ⇒ Object
- #get_ip_address ⇒ Object
- #log_activity(key, changes, owner, ip_address, object = nil, message = nil) ⇒ Object
- #log_create_activity ⇒ Object
- #log_destroy_activity ⇒ Object
- #log_update_activity ⇒ Object
Instance Method Details
#current_user ⇒ Object
38 39 40 |
# File 'lib/audit_trails/ar_enhanced.rb', line 38 def current_user Thread.current.thread_variable_get('controller').current_user rescue nil end |
#get_ip_address ⇒ Object
42 43 44 |
# File 'lib/audit_trails/ar_enhanced.rb', line 42 def get_ip_address Thread.current.thread_variable_get('controller').get_ip_address rescue '127.0.0.1' end |
#log_activity(key, changes, owner, ip_address, object = nil, message = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/audit_trails/ar_enhanced.rb', line 8 def log_activity(key, changes, owner, ip_address, object = nil, = nil) begin owner_id = owner.id rescue nil AuditTrails::Audit.create(:key => key, :user_id => owner_id, :recipient => object, :parameters => YAML.dump(changes), :message => , :ip_address => ip_address) rescue Exception => ex Rails.logger.error ex. Rails.logger.error ex.backtrace end end |
#log_create_activity ⇒ Object
20 21 22 23 24 |
# File 'lib/audit_trails/ar_enhanced.rb', line 20 def log_create_activity changes = self.changes yield log_activity("#{self.class.name}.create", changes, current_user, get_ip_address, self) unless (self.class.name == 'ActiveRecord::SchemaMigration') end |
#log_destroy_activity ⇒ Object
32 33 34 35 36 |
# File 'lib/audit_trails/ar_enhanced.rb', line 32 def log_destroy_activity changes = self.changes yield log_activity("#{self.class.name}.destroy", changes, current_user, get_ip_address, self) end |
#log_update_activity ⇒ Object
26 27 28 29 30 |
# File 'lib/audit_trails/ar_enhanced.rb', line 26 def log_update_activity changes = self.changes yield log_activity("#{self.class.name}.update", changes, current_user, get_ip_address, self) end |