Class: RailsVisualizer::Schema::ModelInspector

Inherits:
Object
  • Object
show all
Includes:
PathHelper
Defined in:
lib/rails_visualizer/schema/model_inspector.rb

Constant Summary collapse

SERIALIZABLE_TYPES =
[String, Symbol, Integer, Float, TrueClass, FalseClass, NilClass, Array, Hash].freeze
CALLBACK_TYPES =
%w[validate save create update destroy commit rollback find initialize touch].freeze

Instance Method Summary collapse

Constructor Details

#initialize(model, schema_cache = nil, file_cache = nil, method_location_cache = nil) ⇒ ModelInspector

file_cache and method_location_cache are shared across all ModelInspector instances in a single run to avoid redundant file reads and instance_method lookups for concern/parent methods included by many models.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rails_visualizer/schema/model_inspector.rb', line 14

def initialize(model, schema_cache = nil, file_cache = nil, method_location_cache = nil)
  @model                 = model
  @schema_cache          = schema_cache
  @file_cache            = file_cache || {}
  @method_location_cache = method_location_cache || {}
  @index_map             = if schema_cache
                             schema_cache.index_map_for(model.table_name)
                           else
                             IndexInspector.new(model).call
                           end
  @method_cache          = {}
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails_visualizer/schema/model_inspector.rb', line 27

def call
  {
    name: @model.name,
    table_name: @model.table_name,
    abstract: false,
    file_path: source_path_for(@model),
    columns: columns,
    associations: associations,
    validations: validations,
    enums: enums,
    scopes: scopes,
    callbacks: callbacks
  }
end