Module: ConcernsOnRails::Models::Anonymizable::ClassMethods
- Includes:
- Support::ColumnGuard
- Defined in:
- lib/concerns_on_rails/models/anonymizable.rb
Instance Method Summary collapse
-
#anonymizable(*fields, with:, stamp: UNSET, clear_audit_trail: UNSET, prefix: nil, suffix: nil) ⇒ Object
Declare fields and their erasure strategy.
-
#anonymize_all! ⇒ Object
Anonymize every matching record that isn't already stamped, in one transaction.
Methods included from Support::ColumnGuard
#ensure_columns!, #ensure_columns_on!, #schema_reachable?
Instance Method Details
#anonymizable(*fields, with:, stamp: UNSET, clear_audit_trail: UNSET, prefix: nil, suffix: nil) ⇒ Object
Declare fields and their erasure strategy. Repeatable — field rules merge across calls; stamp:/clear_audit_trail:/prefix:/suffix: apply only when explicitly passed (last explicit value wins).
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/concerns_on_rails/models/anonymizable.rb', line 91 def anonymizable(*fields, with:, stamp: UNSET, clear_audit_trail: UNSET, prefix: nil, suffix: nil) raise ArgumentError, "#{LABEL}: at least one field is required" if fields.empty? strategy = anonymizable_resolve_strategy(with) (stamp, clear_audit_trail) ensure_columns!(LABEL, fields) ensure_columns!(LABEL, anonymizable_stamp) if anonymizable_stamp self.anonymizable_rules = anonymizable_rules.merge(fields.to_h { |f| [f.to_sym, strategy] }) anonymizable_define_scopes(prefix, suffix) end |
#anonymize_all! ⇒ Object
Anonymize every matching record that isn't already stamped, in one transaction. Returns the Integer count of records anonymized (the 1.22 batch contract). Without a stamp column every record matches.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/concerns_on_rails/models/anonymizable.rb', line 107 def anonymize_all! transaction do all.to_a.count do |record| next false if record.anonymized? record.anonymize! true end end end |