Class: VisualModels::ModelsToGraph

Inherits:
Object
  • Object
show all
Defined in:
app/services/visual_models/models_to_graph.rb

Constant Summary collapse

POLY_NODE_PREFIX =
'<polymorphic:'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope: nil) ⇒ ModelsToGraph

Returns a new instance of ModelsToGraph.



56
57
58
59
60
61
62
63
# File 'app/services/visual_models/models_to_graph.rb', line 56

def initialize(scope: nil)
  @scope_label = scope&.to_s
  @nodes       = []
  @links       = []
  @poly_nodes  = {}
  @sti_links   = []
  @views_cache = {}
end

Class Method Details

.call(scope: nil) ⇒ Object



52
53
54
# File 'app/services/visual_models/models_to_graph.rb', line 52

def self.call(scope: nil)
  new(scope: scope).call
end

Instance Method Details

#callObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/services/visual_models/models_to_graph.rb', line 65

def call
  eager_load!
  models = scoped_models

  models.each { |m| @nodes << build_node(m) }
  models.each { |m| collect_links_for(m, models) }
  collect_polymorphic_candidates(models)
  collect_sti_for(models)

  {
    nodes:                @nodes,
    links:                @links,
    polymorphic_targets:  @poly_nodes.values,
    sti_links:            @sti_links,
    databases:            @nodes.map { |n| n[:database] }.compact.uniq.sort
  }
end