Sha256: 237b14cc6a031f0757beaed62ab0dd7a3eccc11c00fa1fa2cb89a3ebb21fcf0f

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

require 'indented_io'

module PgGraph::Type
  class Node
    def dump(children = self.children.values.sort_by(&:name), link_info: false, super_table: nil)
      print identifier + (super_table ? " < #{super_table}" : "")
      puts
      indent { children.each { |child| child.dump(link_info: link_info) } }
    end
  end

  class Schema
    def dump(link_info: false)
      super(record_types.sort_by(&:name), link_info: link_info)
    end
  end

  class RecordType
    def dump(**opts)
      super_table = table.super_table&.identifier
      columns = fields.reject { |column|
        column.primary_key? || column.name =~ /_id$/ || column.name =~ /_kind$/ # FIXME
      }
      super(columns, super_table: super_table, **opts)
    end
  end

  class Column
    def dump(link_info: false)
      print "#{identifier}: "
      method = type.schema == record_type.schema ? :identifier : :schema_identifier
      if self.is_a?(MmTableColumn) && !self.is_a?(NmTableColumn)
        type_identifier = "{[#{type.element_type.send(method)}]}"
      else
        type_identifier = type.send(method)
      end
      print type_identifier
      print "()" if generated?
      print "[#{that_link_column}]" if kind?
      print "?" if nullable?
      print "!" if unique?
      dump_type if link_info
      puts
    end

    def dump_type() end
  end

  class RecordColumn
    def dump_type
      print " (#{this_link_column} -> #{type.table.name}.#{that_link_column}) (RecordColumn)"
    end
  end

  class TableColumn
    def dump_type
      print " (#{this_link_column} -> #{type.table.name}.#{that_link_column}) (TableColumn)"
    end
  end

  class MmTableColumn
    def dump_type
      print \
          " (#{this_link_column} -> #{mm_table.name}.#{this_mm_column}," +
          " #{mm_table.name}.#{that_mm_column} -> #{that_table.name}.#{that_link_column}) (MmTableColumn)"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pg_graph-0.5.2 lib/pg_graph/type/dump_type.rb
pg_graph-0.5.1 lib/pg_graph/type/dump_type.rb
pg_graph-0.5.0 lib/pg_graph/type/dump_type.rb
pg_graph-0.4.2 lib/pg_graph/type/dump_type.rb
pg_graph-0.4.1 lib/pg_graph/type/dump_type.rb
pg_graph-0.4.0 lib/type/dump_type.rb