Class: Verd::Graph
- Inherits:
-
Object
- Object
- Verd::Graph
- Defined in:
- lib/verd.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
Instance Method Summary collapse
- #categories ⇒ Object
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
- #links ⇒ Object
- #models ⇒ Object
- #nodes ⇒ Object
- #plain_categories ⇒ Object
- #relations ⇒ Object
- #to_h ⇒ Object
- #to_html ⇒ Object
- #to_json ⇒ Object
- #write_html ⇒ Object
Constructor Details
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
11 12 13 |
# File 'lib/verd.rb', line 11 def domain @domain end |
Instance Method Details
#categories ⇒ Object
48 49 50 51 52 |
# File 'lib/verd.rb', line 48 def categories plain_categories.map do |d| {name: d} end end |
#links ⇒ Object
44 45 46 |
# File 'lib/verd.rb', line 44 def links relations.map(&:verd_link) end |
#models ⇒ Object
26 27 28 29 30 |
# File 'lib/verd.rb', line 26 def models @models ||= relations.each_with_object(Set.new) do |rel, s| s << rel.destination.model << rel.source.model end.sort_by(&:name) end |
#nodes ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/verd.rb', line 32 def nodes models.map do |model| category = plain_categories.index(model.source_dir) { name: model.name, category: category, schema: model.verd_columns, indexes: model.verd_indexes } end end |
#plain_categories ⇒ Object
54 55 56 57 58 |
# File 'lib/verd.rb', line 54 def plain_categories @categories ||= models.each_with_object(Set.new) do |m, s| s << m.source_dir end.sort end |
#relations ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/verd.rb', line 17 def relations @relations ||= domain.relationships.each_with_object({}) do |rel, rs| next if rel.destination.model.nil? || rel.source.model.nil? rs[[rel.source.model, rel.destination.model]] = rel end.values.sort_by do |rel| [rel.source.model.name, rel.destination.model.name] end end |
#to_h ⇒ Object
60 61 62 |
# File 'lib/verd.rb', line 60 def to_h {nodes: nodes, links: links, categories: categories} end |
#to_html ⇒ Object
68 69 70 71 |
# File 'lib/verd.rb', line 68 def to_html tmpl = File.join(__dir__, 'verd', 'template.html') File.read(tmpl).sub(/\/\/start-sub.*\/\/end-sub/m, to_json) end |
#to_json ⇒ Object
64 65 66 |
# File 'lib/verd.rb', line 64 def to_json JSON.pretty_generate(to_h) end |
#write_html ⇒ Object
73 74 75 76 |
# File 'lib/verd.rb', line 73 def write_html path = File.join Rails.root.to_s, 'verd.html' File.open(path, 'w'){ |f| f.puts to_html } end |