module Anony::Anonymisable
The main Anony
object to include in your ActiveRecord class.
@example Using in a single model
class Manager < ApplicationRecord include Anony::Anonymisable end
@example Making this available to your whole application
class ApplicationRecord < ActiveRecord::Base include Anony::Anonymisable end
Public Class Methods
included(base)
click to toggle source
@!visibility private
# File lib/anony/anonymisable.rb, line 78 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
anonymise!()
click to toggle source
Run all anonymisation strategies on the model instance before saving it.
@return [Anony::Result] described if the save was successful, and the fields or errors created @example
manager = Manager.first manager.anonymise!
# File lib/anony/anonymisable.rb, line 66 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