Module: Anony::Anonymisable

Defined in:
lib/anony/anonymisable.rb

Overview

The main Anony object to include in your ActiveRecord class.

Examples:

Using in a single model

class Manager < ApplicationRecord
  include Anony::Anonymisable
end

Making this available to your whole application

class ApplicationRecord < ActiveRecord::Base
  include Anony::Anonymisable
end

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#anonymise!Anony::Result

Run all anonymisation strategies on the model instance before saving it.

Examples:

manager = Manager.first
manager.anonymise!

Returns:

  • (Anony::Result)

    described if the save was successful, and the fields or errors created



91
92
93
94
95
96
97
98
99
100
# File 'lib/anony/anonymisable.rb', line 91

def anonymise!
  unless self.class.anonymise_config
    raise ArgumentError, "#{self.class.name} does not have an Anony configuration"
  end

  self.class.anonymise_config.validate!
  self.class.anonymise_config.apply(self)
rescue ActiveRecord::RecordNotSaved, ActiveRecord::RecordNotDestroyed => e
  Result.failed(e)
end

#anonymised?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/anony/anonymisable.rb', line 102

def anonymised?
  anonymised_at.present?
end