Class: Pgerd::Erd::ViewNode

Inherits:
Object
  • Object
show all
Defined in:
lib/pgerd/erd/view_node.rb

Constant Summary collapse

VIEW_TEMPLATE =
"<table border=\"1\" align=\"center\" cellborder=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n  <tr><td bgcolor=\"#fafaf8\" align=\"center\" cellpadding=\"8\"><font point-size=\"11\"><%= name %> *view*</font></td></tr>\n  <% grouped_columns.each_with_index do |group, index| %>\n    <% if index > 0 %>\n      <tr><td height='3'></td></tr>\n    <% end %>\n    <% group.each do |column| %>\n      <tr>\n        <td align=\"left\" port=\"<%= column.name %>\"><%= column.name %>   <font color=\"grey60\"><%= column.abbreviated_data_type %></font></td>\n      </tr>\n    <% end %>\n  <% end %>\n</table>\n"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view, options = {}) ⇒ ViewNode

Returns a new instance of ViewNode.



24
25
26
27
28
29
30
# File 'lib/pgerd/erd/view_node.rb', line 24

def initialize(view, options = {})
  @view = view

  @groups_to_hide = []
  @groups_to_hide << :id unless options.fetch(:show_id, true)
  @groups_to_hide << :timestamps unless options.fetch(:show_timestamps, true)
end

Instance Attribute Details

#groups_to_hideObject (readonly)

Returns the value of attribute groups_to_hide.



22
23
24
# File 'lib/pgerd/erd/view_node.rb', line 22

def groups_to_hide
  @groups_to_hide
end

#viewObject (readonly)

Returns the value of attribute view.



22
23
24
# File 'lib/pgerd/erd/view_node.rb', line 22

def view
  @view
end

Class Method Details

.render(view, options = {}) ⇒ Object



32
33
34
# File 'lib/pgerd/erd/view_node.rb', line 32

def self.render(view, options = {})
  new(view, options).to_html
end

Instance Method Details

#to_htmlObject



36
37
38
39
40
41
42
43
# File 'lib/pgerd/erd/view_node.rb', line 36

def to_html
  grouped_columns = @view.columns
    .reject { |column| @groups_to_hide.include? column.group }
    .group_by(&:group)
    .values

  ErbalT.new(name: @view.name, grouped_columns: grouped_columns).render(VIEW_TEMPLATE).strip
end