rails-mermaid_erd_markdown 0.3.2 → 0.4.0
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 +4 -4
- data/CHANGELOG.md +4 -1
- data/Gemfile.lock +1 -1
- data/README.md +7 -2
- data/docs/examples/erd.yml +3 -0
- data/lib/rails-mermaid_erd_markdown/configuration.rb +5 -2
- data/lib/rails-mermaid_erd_markdown/source_data.rb +35 -1
- data/lib/rails-mermaid_erd_markdown/version.rb +1 -1
- data/test/mock_data/models.rb +6 -6
- data/test/test_rails/rails-mermaid_erd_markdown/test_generator.rb +1 -1
- data/test/test_rails/rails-mermaid_erd_markdown/test_source_data.rb +35 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1334a132131725a23b89678a03b5a74ce0d8eb1feda6f737d0aff4d25534001
|
4
|
+
data.tar.gz: 77267051ff9f9e18a73ba908be5ba477b29688b94f9714463f032ad2208e41de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddf34c03bde1e6377faab02252e48c677a23b49f54cb01e66d6cc68edfdca9a1b9de95b2bd20fb40e5244c83e055736da54208669e31f1dfd0acaf15cd5e17d5
|
7
|
+
data.tar.gz: 9da5893f0c23fca841e638c7886716e06f44156b5bf4cf54661806cddd039896227fddfa2c44f822dd04dd88db9dee7df58a8f4697b7bd58992791c3bdd4d6a3
|
data/CHANGELOG.md
CHANGED
@@ -17,4 +17,7 @@
|
|
17
17
|
- Change rails-mermaid_erd version dependency to at least 0.4.2
|
18
18
|
|
19
19
|
## [0.3.2] - 2024-08-10
|
20
|
-
- (HOTFIX) Fix bundler + lockfile out-of-sync issues
|
20
|
+
- (HOTFIX) Fix bundler + lockfile out-of-sync issues
|
21
|
+
|
22
|
+
## [0.4.0] - 2024-08-31
|
23
|
+
- [Feature] Filter out specified models from ERDs
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# rails-mermaid_erd_markdown
|
2
2
|
|
3
|
-
A Ruby on Rails gem that extends rails-mermaid_erd to generate mermaid Entity-Relationship Diagrams (ERD) for ActiveRecord Models. When combined with Continuous Integration (CI) pipelines, it enables one to generate living, self-updating documentation of their data.
|
3
|
+
A Ruby on Rails gem that extends [rails-mermaid_erd](https://github.com/koedame/rails-mermaid_erd) to generate mermaid Entity-Relationship Diagrams (ERD) for ActiveRecord Models in markdown. When combined with Continuous Integration (CI) pipelines, it enables one to generate living, self-updating documentation of their data.
|
4
4
|
|
5
|
-
## Example
|
5
|
+
## Example Entity-Relationship Diagram
|
6
6
|
|
7
7
|
```mermaid
|
8
8
|
erDiagram
|
@@ -67,11 +67,16 @@ erd:
|
|
67
67
|
output_path: 'app/ERD.md' # Set output path of ERDs, default: 'app/ERD.md'
|
68
68
|
split_output: false, # Generates individual ERDs for each model with a specified depth, default: false
|
69
69
|
relationship_depth: 1 # Configured depth of individual ERD model generation, default: 1
|
70
|
+
ignored_models: # Models to be filtered out of all ERDs (case-sensitive), default: []
|
71
|
+
- Article
|
72
|
+
- Comment
|
70
73
|
|
71
74
|
```
|
72
75
|
|
73
76
|
If your entity diagram is too large to be displayed you can set a `split_output` configuration to `true` to generate multiple ERD files based on each model in your project.
|
74
77
|
|
78
|
+
Or you can specify the models to be filtered out of the ERDs using `ignored_models`
|
79
|
+
|
75
80
|
You can also set a `relationship_depth` configuration to include more than 1 level (the default) of associations in each document.
|
76
81
|
|
77
82
|
|
data/docs/examples/erd.yml
CHANGED
@@ -2,3 +2,6 @@ erd:
|
|
2
2
|
output_path: 'app/ERD.md' # Set output path of ERDs, default: 'app/ERD.md'
|
3
3
|
split_output: false, # Generates individual ERDs for each model with a specified depth, default: false
|
4
4
|
relationship_depth: 1 # Configured depth of individual ERD model generation, default: 1
|
5
|
+
ignored_models: # Models to be filtered out of all ERDs (case-sensitive)
|
6
|
+
- Article
|
7
|
+
- Comment
|
@@ -4,13 +4,14 @@ require "yaml"
|
|
4
4
|
|
5
5
|
module MermaidErdMarkdown
|
6
6
|
class Configuration
|
7
|
-
attr_accessor :output_path, :split_output, :relationship_depth
|
7
|
+
attr_accessor :output_path, :split_output, :relationship_depth, :ignored_models
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
config = {
|
11
11
|
output_path: "app/models/ERD.md",
|
12
12
|
split_output: false,
|
13
|
-
relationship_depth: 1
|
13
|
+
relationship_depth: 1,
|
14
|
+
ignored_models: []
|
14
15
|
}
|
15
16
|
erd_config_path = "erd.yml"
|
16
17
|
|
@@ -19,10 +20,12 @@ module MermaidErdMarkdown
|
|
19
20
|
@output_path = erd_yml["erd"]["output_path"] || config[:output_path]
|
20
21
|
@split_output = erd_yml["erd"]["split_output"] || config[:split_output]
|
21
22
|
@relationship_depth = erd_yml["erd"]["relationship_depth"] || config[:relationship_depth]
|
23
|
+
@ignored_models = erd_yml["erd"]["ignored_models"] || config[:ignored_models]
|
22
24
|
rescue StandardError
|
23
25
|
@output_path = config[:output_path]
|
24
26
|
@split_output = config[:split_output]
|
25
27
|
@relationship_depth = config[:relationship_depth]
|
28
|
+
@ignored_models = config[:ignored_models]
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rails-mermaid_erd"
|
4
|
+
require "active_support"
|
5
|
+
require "active_support/core_ext/enumerable"
|
6
|
+
require "active_support/core_ext/object"
|
4
7
|
|
5
8
|
module MermaidErdMarkdown
|
6
9
|
class SourceData
|
7
10
|
def data
|
8
|
-
@data ||=
|
11
|
+
@data ||= generate_model_data
|
9
12
|
end
|
10
13
|
|
11
14
|
def split_output(depth = 1)
|
@@ -41,6 +44,37 @@ module MermaidErdMarkdown
|
|
41
44
|
|
42
45
|
private
|
43
46
|
|
47
|
+
def configuration
|
48
|
+
@configuration ||= MermaidErdMarkdown::Configuration.new
|
49
|
+
end
|
50
|
+
|
51
|
+
def generate_model_data
|
52
|
+
raw_data = RailsMermaidErd::Builder.model_data
|
53
|
+
|
54
|
+
return raw_data unless filter_model_data?
|
55
|
+
|
56
|
+
filter_model_data(raw_data)
|
57
|
+
end
|
58
|
+
|
59
|
+
def filter_model_data?
|
60
|
+
configuration.ignored_models.present?
|
61
|
+
end
|
62
|
+
|
63
|
+
def filter_model_data(raw_data)
|
64
|
+
filtered_data = {}
|
65
|
+
filtered_data[:Models] = raw_data[:Models].select do |model_hash|
|
66
|
+
not_filtered?(model_hash[:ModelName])
|
67
|
+
end
|
68
|
+
filtered_data[:Relations] = raw_data[:Relations].select do |relation_hash|
|
69
|
+
not_filtered?(relation_hash[:LeftModelName]) && not_filtered?(relation_hash[:RightModelName])
|
70
|
+
end
|
71
|
+
filtered_data
|
72
|
+
end
|
73
|
+
|
74
|
+
def not_filtered?(model_name)
|
75
|
+
configuration.ignored_models.exclude?(model_name)
|
76
|
+
end
|
77
|
+
|
44
78
|
def models(model_names, source_models)
|
45
79
|
model_names.map do |model_name|
|
46
80
|
source_models.find { |m| m[:ModelName] == model_name }
|
data/test/mock_data/models.rb
CHANGED
@@ -54,7 +54,7 @@ module MockData
|
|
54
54
|
}
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
57
|
+
def article_user_relation
|
58
58
|
{
|
59
59
|
LeftModelName: "Article",
|
60
60
|
LeftValue: "}o",
|
@@ -65,7 +65,7 @@ module MockData
|
|
65
65
|
}
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
68
|
+
def profile_user_relation
|
69
69
|
{
|
70
70
|
LeftModelName: "Profile",
|
71
71
|
LeftValue: "}o",
|
@@ -76,7 +76,7 @@ module MockData
|
|
76
76
|
}
|
77
77
|
end
|
78
78
|
|
79
|
-
def
|
79
|
+
def comment_article_relation
|
80
80
|
{
|
81
81
|
LeftModelName: "Comment",
|
82
82
|
LeftValue: "}o",
|
@@ -95,9 +95,9 @@ module MockData
|
|
95
95
|
article_model,
|
96
96
|
comment_model
|
97
97
|
], Relations: [
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
article_user_relation,
|
99
|
+
profile_user_relation,
|
100
|
+
comment_article_relation
|
101
101
|
]
|
102
102
|
}
|
103
103
|
end
|
@@ -32,7 +32,7 @@ class MermaidErdMarkdown::GeneratorTest < Minitest::Test
|
|
32
32
|
|
33
33
|
source = {
|
34
34
|
Models: [user_model, article_model, profile_model],
|
35
|
-
Relations: [
|
35
|
+
Relations: [article_user_relation, profile_user_relation]
|
36
36
|
}
|
37
37
|
|
38
38
|
result = MermaidErdMarkdown::Generator.new.model_markdown(source)
|
@@ -9,19 +9,19 @@ class MermaidErdMarkdown::SourceDataTest < Minitest::Test
|
|
9
9
|
def test_split_output
|
10
10
|
expected_user = {
|
11
11
|
Models: [user_model, article_model, profile_model],
|
12
|
-
Relations: [
|
12
|
+
Relations: [article_user_relation, profile_user_relation]
|
13
13
|
}
|
14
14
|
expected_profile = {
|
15
15
|
Models: [profile_model, user_model],
|
16
|
-
Relations: [
|
16
|
+
Relations: [profile_user_relation]
|
17
17
|
}
|
18
18
|
expected_article = {
|
19
19
|
Models: [article_model, user_model, comment_model],
|
20
|
-
Relations: [
|
20
|
+
Relations: [article_user_relation, comment_article_relation]
|
21
21
|
}
|
22
22
|
expected_comment = {
|
23
23
|
Models: [comment_model, article_model],
|
24
|
-
Relations: [
|
24
|
+
Relations: [comment_article_relation]
|
25
25
|
}
|
26
26
|
expected = [
|
27
27
|
expected_user,
|
@@ -40,19 +40,19 @@ class MermaidErdMarkdown::SourceDataTest < Minitest::Test
|
|
40
40
|
def test_split_output_with_depth
|
41
41
|
expected_user = {
|
42
42
|
Models: [user_model, article_model, profile_model, comment_model],
|
43
|
-
Relations: [
|
43
|
+
Relations: [article_user_relation, profile_user_relation, comment_article_relation]
|
44
44
|
}
|
45
45
|
expected_profile = {
|
46
46
|
Models: [profile_model, user_model, article_model],
|
47
|
-
Relations: [
|
47
|
+
Relations: [profile_user_relation, article_user_relation]
|
48
48
|
}
|
49
49
|
expected_article = {
|
50
50
|
Models: [article_model, user_model, comment_model, profile_model],
|
51
|
-
Relations: [
|
51
|
+
Relations: [article_user_relation, comment_article_relation, profile_user_relation]
|
52
52
|
}
|
53
53
|
expected_comment = {
|
54
54
|
Models: [comment_model, article_model, user_model],
|
55
|
-
Relations: [
|
55
|
+
Relations: [comment_article_relation, article_user_relation]
|
56
56
|
}
|
57
57
|
expected = [
|
58
58
|
expected_user,
|
@@ -67,4 +67,31 @@ class MermaidErdMarkdown::SourceDataTest < Minitest::Test
|
|
67
67
|
assert_equal expected, result
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
71
|
+
def test_data_filtered
|
72
|
+
stub_config = Minitest::Mock.new
|
73
|
+
|
74
|
+
def stub_config.output_path; "app/models/ERD.md"; end
|
75
|
+
def stub_config.split_output; false; end
|
76
|
+
def stub_config.relationship_depth; 1; end
|
77
|
+
def stub_config.ignored_models; ['User']; end
|
78
|
+
|
79
|
+
expected = {
|
80
|
+
Models: [
|
81
|
+
profile_model,
|
82
|
+
article_model,
|
83
|
+
comment_model
|
84
|
+
], Relations: [
|
85
|
+
comment_article_relation
|
86
|
+
]
|
87
|
+
}
|
88
|
+
|
89
|
+
RailsMermaidErd::Builder.stub :model_data, stubbed_model_data do
|
90
|
+
MermaidErdMarkdown::Configuration.stub :new, stub_config do
|
91
|
+
result = MermaidErdMarkdown::SourceData.new.data
|
92
|
+
|
93
|
+
assert_equal expected, result
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
70
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-mermaid_erd_markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- humzahkiani
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|