Module: GdprAdmin::Helpers::PaperTrailHelper

Includes:
FieldAnonymizerHelper
Included in:
EraseHelper
Defined in:
lib/gdpr_admin/helpers/paper_trail_helper.rb

Instance Method Summary collapse

Methods included from FieldAnonymizerHelper

#anonymize_field, #nilify, #nullify, #with_seed

Methods included from Anonymizers::InternetAnonymizer

#anonymize_email, #anonymize_ip, #anonymize_password, #mask_ip

Methods included from Anonymizers::ContactAnonymizer

#anonymize_city, #anonymize_country, #anonymize_country_code2, #anonymize_country_code3, #anonymize_phone_number, #anonymize_state, #anonymize_street_address, #anonymize_zip

Methods included from Anonymizers::CompanyAnonymizer

#anonymize_company

Methods included from Anonymizers::NameAnonymizer

#anonymize_first_name, #anonymize_last_name, #anonymize_name

Instance Method Details

#anonymize_version_object(version, fields) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gdpr_admin/helpers/paper_trail_helper.rb', line 22

def anonymize_version_object(version, fields)
  object = version.object.deep_dup
  return object if object.blank?
  return {} if object.is_a?(Array)

  fields.each do |field|
    field_name = field[:field].to_s
    field_value = object[field_name]
    next if field_value.nil?

    new_value = anonymize_field_value(version.item, field.merge(seed: field_value))
    object.merge!(field_name => new_value)
  end
  object
end

#anonymize_version_object_changes(version, fields) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gdpr_admin/helpers/paper_trail_helper.rb', line 38

def anonymize_version_object_changes(version, fields)
  return unless version.respond_to?(:object_changes)

  object_changes = version.object_changes.deep_dup
  return object_changes if object_changes.blank?
  return {} if object_changes.is_a?(Array)

  fields.each do |field|
    field_name = field[:field].to_s
    changes = object_changes[field_name]
    next if changes.nil?

    new_value = anonymize_object_changes_array(version, changes, field)
    object_changes.merge!(field_name => new_value)
  end
  object_changes
end

#without_paper_trailObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gdpr_admin/helpers/paper_trail_helper.rb', line 10

def without_paper_trail
  return yield unless defined?(::PaperTrail)

  begin
    current_status = ::PaperTrail.enabled?
    ::PaperTrail.enabled = false
    yield
  ensure
    ::PaperTrail.enabled = current_status
  end
end