Class: ActiveRecord::DataClassification::ModelReflection

Inherits:
Object
  • Object
show all
Includes:
Aggregate::Extension
Defined in:
lib/active_record/data_classification/model_reflection.rb

Constant Summary

Constants included from Aggregate::Extension

Aggregate::Extension::AGGREGATE_BUILTINS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, models) ⇒ ModelReflection

Returns a new instance of ModelReflection.



8
9
10
11
12
13
14
15
16
# File 'lib/active_record/data_classification/model_reflection.rb', line 8

def initialize(table_name, models)
  @models = models
  @model  = @models.find { |m| m.try(:base_class) == m } || @models.first

  @server_type = find_server_type(table_name)

  @model_name = @model.name
  @table_name = table_name
end

Instance Attribute Details

#model_nameObject (readonly)

Returns the value of attribute model_name.



6
7
8
# File 'lib/active_record/data_classification/model_reflection.rb', line 6

def model_name
  @model_name
end

#server_typeObject (readonly)

Returns the value of attribute server_type.



6
7
8
# File 'lib/active_record/data_classification/model_reflection.rb', line 6

def server_type
  @server_type
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



6
7
8
# File 'lib/active_record/data_classification/model_reflection.rb', line 6

def table_name
  @table_name
end

Instance Method Details

#columnsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_record/data_classification/model_reflection.rb', line 18

def columns
  connection.columns(table_name).map do |column|
    column_spec = @model.try(:field_specs)&.[](column.name)
    Column.new(
      column.name,
      column.sql_type,
      sensitivity_friendly(@models, column_spec&.data_security),
      sensitivity_source(@models, column_spec&.data_security),
      anonymization_type || column_spec&.anonymize_using,
      @models
    )
  end
end