Module: AuditModel::Models::Helpers::ClassMethods

Defined in:
lib/audit_model/models/helpers.rb

Instance Method Summary collapse

Instance Method Details

#auditable(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/audit_model/models/helpers.rb', line 7

def auditable(options = {}) 
  send :include, InstanceMethods
  class_attribute :audit_enabled, instance_writer: false
  options[:on] ||= [:create, :update, :destroy]
  setup_callbacks options[:on]
  setup_model
  setup_associations

  send :enable_audit
end

#disable_auditObject



26
27
28
# File 'lib/audit_model/models/helpers.rb', line 26

def disable_audit
  self.audit_enabled = false
end

#enable_auditObject



30
31
32
# File 'lib/audit_model/models/helpers.rb', line 30

def enable_audit
  self.audit_enabled = true
end

#without_auditObject



18
19
20
21
22
23
24
# File 'lib/audit_model/models/helpers.rb', line 18

def without_audit 
  cache = audit_enabled
  disable_audit
  yield
ensure
  enable_audit if cache
end