schemerd 0.1.3 → 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: c6867fc6f77949e2e09eff74caa333877a73ec4e87c97202654dd5e350974db7
4
- data.tar.gz: 9320abd1d6db3df30512861c8a044d49c0d7e89ab5e45175b4b3dc9e0967591b
3
+ metadata.gz: ca6f1b673c235b1bdefd3373a34bd56e3d573c2bc9d9e152692937d47335ae58
4
+ data.tar.gz: bb3b90351c3cd8b28679fe9abf9c253405c420dbbc80a7ab589357bffd523195
5
5
  SHA512:
6
- metadata.gz: 5e9b186348b5d726770a0257ec2710e5f2b7f1629855211795b4d1b81ce179ab7ec06672c20e1acbe38fb7f18ab707d48527349b888f9121fd4c56ea413882d3
7
- data.tar.gz: 05f2bf31dd2cb83a1039117e33b1efa0b6e203aab920d386fb9b3791b07dbfb86b77aa8aac031358750886eb275885ff5a2c96c43837097ba9cfed128921ae64
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
 
@@ -60,7 +71,7 @@ module Schemerd
60
71
  model_names = models.map(&:name).to_set
61
72
 
62
73
  models.each do |model|
63
- model.reflect_on_all_associations.each do |assoc|
74
+ model.reflect_on_all_associations.reject { |a| a.options[:through] }.each do |assoc|
64
75
  target_name = assoc.klass.name rescue next
65
76
  next unless model_names.include?(target_name)
66
77
 
@@ -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 << ""
@@ -121,6 +134,8 @@ module Schemerd
121
134
  "#{source} ||--o{ #{target} : \"#{assoc.name}\""
122
135
  when :has_one
123
136
  "#{source} ||--o| #{target} : \"#{assoc.name}\""
137
+ when :has_and_belongs_to_many
138
+ "#{source} }o--o{ #{target} : \"#{assoc.name}\""
124
139
  end
125
140
  end
126
141
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Schemerd
4
- VERSION = "0.1.3"
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.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Monfort