Module: Anony::Anonymisable::ClassMethods

Defined in:
lib/anony/anonymisable.rb

Overview

Mixin containing methods that will be exposed on the ActiveRecord class after including the Anonymisable module.

The primary method, .anonymise, is used to configure the strategies to apply. This configuration is lazily executed when trying to actually anonymise an instance: this is because the database or other lazily-loaded properties are not necessarily available when the class is configured.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#anonymise_configObject (readonly)

Returns the value of attribute anonymise_config.



57
58
59
# File 'lib/anony/anonymisable.rb', line 57

def anonymise_config
  @anonymise_config
end

Instance Method Details

#anonymise { ... } ⇒ Object

Define a set of anonymisation configuration on the ActiveRecord class.

Examples:

class Manager < ApplicationRecord
  anonymise do
    overwrite do
      with_strategy(:first_name) { "ANONYMISED" }
    end
  end
end

Yields:

  • A configuration block

See Also:

  • Anony::Strategies::Overwrite - the methods available inside this block


41
42
43
# File 'lib/anony/anonymisable.rb', line 41

def anonymise(&block)
  @anonymise_config = ModelConfig.new(self, &block)
end

#valid_anonymisation?Boolean

Check whether the model has been configured correctly. Returns a simple ‘true`/`false`. If configuration has not yet been configured, it returns `false`.

Examples:

Manager.valid_anonymisation?

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/anony/anonymisable.rb', line 51

def valid_anonymisation?
  return false unless @anonymise_config

  @anonymise_config.valid?
end