Class: ActiveRecordAnonymizer::AttributesAnonymizer

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_anonymizer/attributes_anonymizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, skip_update: false) ⇒ AttributesAnonymizer

Returns a new instance of AttributesAnonymizer.



7
8
9
10
# File 'lib/active_record_anonymizer/attributes_anonymizer.rb', line 7

def initialize(model, skip_update: false)
  @model = model
  @skip_update = skip_update
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/active_record_anonymizer/attributes_anonymizer.rb', line 5

def model
  @model
end

Instance Method Details

#anonymize_columnsObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/active_record_anonymizer/attributes_anonymizer.rb', line 12

def anonymize_columns
  if model.new_record?
    anonymize_all_attributes
  else
    # Skip updating the record if skip_update is true
    return if @skip_update

    anonymize_changed_columns
  end
end

#populateObject



23
24
25
26
# File 'lib/active_record_anonymizer/attributes_anonymizer.rb', line 23

def populate
  anonymize_all_attributes
  model.save!
end