Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to temporarily disable simple_audit? #6

Open
xuanchien opened this issue Feb 18, 2014 · 1 comment
Open

How to temporarily disable simple_audit? #6

xuanchien opened this issue Feb 18, 2014 · 1 comment

Comments

@xuanchien
Copy link

I integrate simple_audit in a Model, but there are cases that I want to temporarily turn off this simple_audit feature to optimize the performance. Do you guys know how can we do that?

@gtarnovan
Copy link
Owner

Hi,

you would need to add something like this:

# inside the class_eval block in the simple_audit macro definition https://github.com/gtarnovan/simple_audit/blob/master/lib/simple_audit/simple_audit.rb#L47
class << self
  def self.silence_audit
    previously_disabled = self.audit_disabled
    self.audit_disabled = true
    yield
  ensure
    self.audit_disabled = previously_disabled
  end
end

# and update the callbacks https://github.com/gtarnovan/simple_audit/blob/master/lib/simple_audit/simple_audit.rb#L65
after_create {|record| record.class.audit(record, :create) unless record.class.audit_disabled }
after_update {|record| record.class.audit(record, :update) unless record.class.audit_disabled }

That should give you something like this:

    SimpleAudit.silence_audit do
      # no audit performed here
    end

Please fork and try this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants