schemerd 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e389e5da8e102a6cdf0b1d8cffde0204ed9f5d6f1fbbebfa014d0bb05cb380de
4
- data.tar.gz: 686688594764b9159e2f06540436a348b7281a1ccc4337125bb9217581d39825
3
+ metadata.gz: ca6f1b673c235b1bdefd3373a34bd56e3d573c2bc9d9e152692937d47335ae58
4
+ data.tar.gz: bb3b90351c3cd8b28679fe9abf9c253405c420dbbc80a7ab589357bffd523195
5
5
  SHA512:
6
- metadata.gz: 0f7357b7e446b7f62b9e9c56c01646a790b7eec2ea7f0a7adb8429067e83d4db2dd60b92e23be2cf81eb6168ac785550db96145a1a11b5e37f71f52952cf2130
7
- data.tar.gz: 5e6025d37381bfd9310403a33032d106eaf315c26a65ceed14d61c4978c01e8d0b01e5e81654eea95704d81d82128afa9c8a6a763375535bff01a09741c774cb
6
+ metadata.gz: 4fbb96858dc176e329b092c7ef6badba3064e75f8256252b83e856b8409192066e78c12ac628539ff6ecf44ac454e050694547cdddc7d2ac24d59ce9c1a6588f
7
+ data.tar.gz: 74737e1813ab6e52296db20f5bfc5ab4cab970f73008ba10115b4ba4c44756b6fc3bc3d0489e0e13112948e844001acb590d7fa60c299e2663137033ed28ec13
@@ -27,17 +27,28 @@ module Schemerd
27
27
  Rails.application.eager_load!
28
28
 
29
29
  base = @config.base_class.constantize
30
- base.descendants
30
+ all_models = base.descendants
31
31
  .reject(&:abstract_class?)
32
32
  .reject { |m| excluded?(m.name) }
33
33
  .select { |m| m.table_exists? rescue false }
34
- .sort_by(&:name)
34
+
35
+ @sti_children = Hash.new { |h, k| h[k] = [] }
36
+ sti, non_sti = all_models.partition { |m| sti_child?(m) }
37
+ sti.each { |m| @sti_children[m.superclass.name] << m.name }
38
+
39
+ non_sti.sort_by(&:name)
35
40
  end
36
41
 
37
42
  def excluded?(model_name)
38
43
  @config.excluded_prefixes.any? { |prefix| model_name.start_with?(prefix) }
39
44
  end
40
45
 
46
+ def sti_child?(model)
47
+ model.superclass != @config.base_class.constantize &&
48
+ !model.superclass.abstract_class? &&
49
+ model.table_name == model.superclass.table_name
50
+ end
51
+
41
52
  def build_diagram(models)
42
53
  lines = []
43
54
 
@@ -81,10 +92,12 @@ module Schemerd
81
92
 
82
93
  models.each do |model|
83
94
  lines << " #{model.name} {"
95
+ subtypes = @sti_children.fetch(model.name, [])
84
96
  sort_columns(model.columns).each do |col|
85
97
  pk = col.name == model.primary_key ? "PK" : ""
98
+ comment = col.name == "type" && subtypes.any? ? "\"#{subtypes.sort.join(', ')}\"" : ""
86
99
  type = col.type || "string"
87
- lines << " #{type} #{col.name} #{pk}".rstrip
100
+ lines << " #{type} #{col.name} #{pk} #{comment}".rstrip
88
101
  end
89
102
  lines << " }"
90
103
  lines << ""
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Schemerd
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schemerd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Monfort