Class: ActiveRecordAnonymizer::Initiator
- Inherits:
-
Object
- Object
- ActiveRecordAnonymizer::Initiator
- Defined in:
- lib/active_record_anonymizer/initiator.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#column_name ⇒ Object
readonly
Returns the value of attribute column_name.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#with ⇒ Object
readonly
Returns the value of attribute with.
Instance Method Summary collapse
- #configure_anonymization ⇒ Object
-
#initialize(model, attributes, with: nil, column_name: nil) ⇒ Initiator
constructor
A new instance of Initiator.
-
#validate ⇒ Object
TODO: Extract this logic in a seperate Validation module/class.
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/active_record_anonymizer/initiator.rb', line 5 def attributes @attributes end |
#column_name ⇒ Object (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 |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/active_record_anonymizer/initiator.rb', line 5 def model @model end |
#with ⇒ Object (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_anonymization ⇒ Object
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 |
#validate ⇒ Object
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 |