Class: MermaidErdMarkdown::SourceData

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-mermaid_erd_markdown/source_data.rb

Instance Method Summary collapse

Instance Method Details

#dataObject



10
11
12
# File 'lib/rails-mermaid_erd_markdown/source_data.rb', line 10

def data
  @data ||= generate_model_data
end

#split_output(depth = 1) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rails-mermaid_erd_markdown/source_data.rb', line 14

def split_output(depth = 1)
  source_models = data[:Models]
  source_relations = data[:Relations]
  output = []

  source_models.each do |model|
    model_names = [model[:ModelName]]
    search_models = model_names
    relations = []

    depth.times do
      found_relations = []
      next_search_models = []
      search_models.each do |search_model|
        found_relations += related_models(search_model, source_relations)
        next_search_models += related_model_names(search_model, found_relations)
      end
      search_models = next_search_models
      model_names += search_models
      relations += found_relations
    end

    output << {
      Models: models(model_names.uniq, source_models),
      Relations: relations.uniq
    }
  end

  output
end