Class: ActiveRecordAnonymizer::Initiator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, attributes, with: nil, column_name: nil) ⇒ Initiator

Returns a new instance of Initiator.



7
8
9
10
11
12
# File 'lib/active_record_anonymizer/initiator.rb', line 7

def initialize(model, attributes, with: nil, column_name: nil)
  @model = model
  @attributes = attributes
  @with = with
  @column_name = column_name
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#column_nameObject (readonly)

Returns the value of attribute column_name.



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

def column_name
  @column_name
end

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

#withObject (readonly)

Returns the value of attribute with.



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

def with
  @with
end

Instance Method Details

#configure_anonymizationObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_record_anonymizer/initiator.rb', line 20

def configure_anonymization
  attributes.each do |attribute|
    anonymized_column = anonymized_column_name(attribute)

    # I don't like that we're manipulating the class attribute here
    # This breaks the SRP for this method
    # TODO:- Will need to revisit how we set the class attribute later
    model.anonymized_attributes[attribute.to_sym] = { column: anonymized_column.to_sym, with: with }

    define_alias_method(attribute, ActiveRecordAnonymizer.configuration.alias_column_name) if ActiveRecordAnonymizer.alias_enabled?
    define_anonymize_method(attribute, anonymized_column)
  end
end

#validateObject

TODO: Extract this logic in a seperate Validation module/class



15
16
17
18
# File 'lib/active_record_anonymizer/initiator.rb', line 15

def validate
  check_for_invalid_arguments(attributes, with, column_name)
  check_for_missing_anonymized_columns(attributes)
end