Module: Audited::Auditor::AuditedClassMethods

Defined in:
lib/audited/auditor.rb

Instance Method Summary collapse

Instance Method Details

#audit_as(user, &block) ⇒ Object

All audit operations during the block are recorded as being made by user. This is not model specific, the method is a convenience wrapper around

See Also:

  • Audit#as_user.


510
511
512
# File 'lib/audited/auditor.rb', line 510

def audit_as(user, &block)
  Audited.audit_class.as_user(user, &block)
end

#audited_columnsObject

Returns an array of columns that are audited. See non_audited_columns



456
457
458
# File 'lib/audited/auditor.rb', line 456

def audited_columns
  @audited_columns ||= column_names - non_audited_columns
end

#auditing_enabledObject



514
515
516
# File 'lib/audited/auditor.rb', line 514

def auditing_enabled
  class_auditing_enabled && Audited.auditing_enabled
end

#auditing_enabled=(val) ⇒ Object



518
519
520
# File 'lib/audited/auditor.rb', line 518

def auditing_enabled=(val)
  Audited.store["#{table_name}_auditing_enabled"] = val
end

#default_ignored_attributesObject



522
523
524
# File 'lib/audited/auditor.rb', line 522

def default_ignored_attributes
  [primary_key, inheritance_column] | Audited.ignored_attributes
end

#disable_auditingObject



498
499
500
# File 'lib/audited/auditor.rb', line 498

def disable_auditing
  self.auditing_enabled = false
end

#enable_auditingObject



502
503
504
# File 'lib/audited/auditor.rb', line 502

def enable_auditing
  self.auditing_enabled = true
end

#non_audited_columnsObject

We have to calculate this here since column_names may not be available when ‘audited` is called



461
462
463
# File 'lib/audited/auditor.rb', line 461

def non_audited_columns
  @non_audited_columns ||= calculate_non_audited_columns
end

#non_audited_columns=(columns) ⇒ Object



465
466
467
468
# File 'lib/audited/auditor.rb', line 465

def non_audited_columns=(columns)
  @audited_columns = nil # reset cached audited columns on assignment
  @non_audited_columns = columns.map(&:to_s)
end

#with_auditingObject

Executes the block with auditing enabled.

Foo.with_auditing do
  @foo.save
end


490
491
492
493
494
495
496
# File 'lib/audited/auditor.rb', line 490

def with_auditing
  auditing_was_enabled = class_auditing_enabled
  enable_auditing
  yield
ensure
  disable_auditing unless auditing_was_enabled
end

#without_auditingObject

Executes the block with auditing disabled.

Foo.without_auditing do
  @foo.save
end


476
477
478
479
480
481
482
# File 'lib/audited/auditor.rb', line 476

def without_auditing
  auditing_was_enabled = class_auditing_enabled
  disable_auditing
  yield
ensure
  enable_auditing if auditing_was_enabled
end