Class: Airview::SchemaInference

Inherits:
Object
  • Object
show all
Defined in:
lib/airview/schema_inference.rb

Constant Summary collapse

SENSITIVE_PATTERNS =
[
  /password/i,
  /token/i,
  /secret/i,
  /api[_-]?key/i,
  /credential/i,
  /encrypted/i,
  /digest/i,
  /reset/i,
  /remember/i
].freeze
TYPE_MAP =
{
  string: :string,
  text: :text,
  integer: :integer,
  float: :float,
  decimal: :decimal,
  boolean: :boolean,
  date: :date,
  datetime: :datetime,
  timestamp: :datetime,
  json: :json,
  jsonb: :json
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ SchemaInference

Returns a new instance of SchemaInference.



33
34
35
# File 'lib/airview/schema_inference.rb', line 33

def initialize(model)
  @model = model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



31
32
33
# File 'lib/airview/schema_inference.rb', line 31

def model
  @model
end

Instance Method Details

#field_attributesObject



51
52
53
54
55
56
57
58
59
# File 'lib/airview/schema_inference.rb', line 51

def field_attributes
  column_fields = model.columns.each_with_index.filter_map do |column, index|
    next if sensitive?(column.name)

    field_attributes_for(column, index)
  end

  column_fields + virtual_field_attributes(column_fields.length)
end

#resource_attributesObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/airview/schema_inference.rb', line 37

def resource_attributes
  {
    key: model.model_name.route_key,
    record_class_name: model.name,
    label: model.model_name.human(count: 2),
    label_method: inferred_label_method,
    enabled: false,
    metadata: {
      table_name: model.table_name,
      inferred_at: Time.current.iso8601
    }
  }
end