Class: Redaction::Redactor

Inherits:
Object
  • Object
show all
Defined in:
lib/redaction/redactor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(models: nil) ⇒ Redactor

Returns a new instance of Redactor.



7
8
9
# File 'lib/redaction/redactor.rb', line 7

def initialize(models: nil)
  @models_to_redact = set_models(models)
end

Instance Attribute Details

#models_to_redactObject (readonly)

Returns the value of attribute models_to_redact.



5
6
7
# File 'lib/redaction/redactor.rb', line 5

def models_to_redact
  @models_to_redact
end

Instance Method Details

#redact!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/redaction/redactor.rb', line 11

def redact!
  raise ProductionEnvironmentError if Rails.env.production?

  models_to_redact.each do |model|
    next if model.redacted_attributes.empty?

    model_progress = progress_bar(model.name, model.count) if Redaction.config.progress_bar

    model.all.unscoped.find_each do |record|
      record.redact!
      model_progress.increment if Redaction.config.progress_bar
    end
  end
end