Skip to content

Commit

Permalink
better default and cleanup only on config change and use the right cl…
Browse files Browse the repository at this point in the history
…ass for comparision
  • Loading branch information
mkristian committed Nov 4, 2011
1 parent 32632f0 commit 25633e3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
3 changes: 0 additions & 3 deletions lib/ixtlan/audit/audit_rack.rb
Expand Up @@ -5,9 +5,6 @@ class AuditRack
def initialize(app, audit_manager) def initialize(app, audit_manager)
@app = app @app = app
@audit_manager = audit_manager @audit_manager = audit_manager
self.class_eval do
include Rails.application.routes.url_helpers
end
end end


def call(env) def call(env)
Expand Down
5 changes: 3 additions & 2 deletions lib/ixtlan/audit/manager.rb
Expand Up @@ -32,8 +32,9 @@ def model=(m)
end end


def keep_logs=(days) def keep_logs=(days)
old = @keep_logs
@keep_logs = days.to_i @keep_logs = days.to_i
daily_cleanup daily_cleanup if old != @keep_logs
end end


def push(message, username) def push(message, username)
Expand Down Expand Up @@ -62,7 +63,7 @@ def username_method
def daily_cleanup def daily_cleanup
if model if model
if(@last_cleanup.nil? || @last_cleanup < 1.days.ago) if(@last_cleanup.nil? || @last_cleanup < 1.days.ago)
@last_cleanup = Date.today @last_cleanup = 0.days.ago # to have the right type
begin begin
delete_all delete_all
logger.info("cleaned audit logs") logger.info("cleaned audit logs")
Expand Down
2 changes: 1 addition & 1 deletion lib/ixtlan/audit/railtie.rb
Expand Up @@ -11,7 +11,7 @@ class Railtie < ::Rails::Railtie
app.config.audit_manager = Manager.new app.config.audit_manager = Manager.new
::ActionController::Base.send(:include, Module) ::ActionController::Base.send(:include, Module)
::ActionController::Base.send(:after_filter, :audit) ::ActionController::Base.send(:after_filter, :audit)
app.config.middleware.use AuditRack, app.config.audit_manager app.config.middleware.use(AuditRack, app.config.audit_manager)
end end
end end


Expand Down
2 changes: 1 addition & 1 deletion lib/ixtlan/audit/user_logger.rb
Expand Up @@ -29,7 +29,7 @@ def log_action(controller, message = nil)
if controller.params[:controller] if controller.params[:controller]
audits = controller.instance_variable_get("@#{controller.params[:controller]}") audits = controller.instance_variable_get("@#{controller.params[:controller]}")
if(audits) if(audits)
"#{controller.params[:controller]}##{controller.params[:action]} #{controller.params[:action].classify}[#{audits.size}]#{as_xml}#{message}" "#{controller.params[:controller]}##{controller.params[:action]} #{controller.params[:controller].classify}[#{audits.size}]#{as_xml}#{message}"
else else
audit = controller.instance_variable_get("@#{controller.params[:controller].singularize}") audit = controller.instance_variable_get("@#{controller.params[:controller].singularize}")
if(audit) if(audit)
Expand Down

0 comments on commit 25633e3

Please sign in to comment.