rails-mermaid_erd_markdown 0.3.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1fc2645eeda1d07ce73a989297a6de24e9a28e8dd2a812bf94dca1eb7d9d0dd8
4
- data.tar.gz: 20534d950c4ab8109286bd708e133516ce4a4e3ce0e7ba8991a664e23e2c0222
3
+ metadata.gz: a1334a132131725a23b89678a03b5a74ce0d8eb1feda6f737d0aff4d25534001
4
+ data.tar.gz: 77267051ff9f9e18a73ba908be5ba477b29688b94f9714463f032ad2208e41de
5
5
  SHA512:
6
- metadata.gz: 4f99bb71981c90be8d6f0c6ad6725133b8e39b2e48664e4bd0dfae24314a24b9dee3045b939e33f5101ce4fd607fb5d5e3768ecd0e85a9e5f8b745bb87ccc248
7
- data.tar.gz: 6980b1b01319af831bfc2798949fae4b85d6dc152e73dcd9469e704a6805711c1ae98cbcea066ea4fb062c153d8d57d2f5580aeea27b2039771656d488563a93
6
+ metadata.gz: ddf34c03bde1e6377faab02252e48c677a23b49f54cb01e66d6cc68edfdca9a1b9de95b2bd20fb40e5244c83e055736da54208669e31f1dfd0acaf15cd5e17d5
7
+ data.tar.gz: 9da5893f0c23fca841e638c7886716e06f44156b5bf4cf54661806cddd039896227fddfa2c44f822dd04dd88db9dee7df58a8f4697b7bd58992791c3bdd4d6a3
data/CHANGELOG.md CHANGED
@@ -1,4 +1,3 @@
1
- ## [Unreleased]
2
1
 
3
2
  ## [0.1.0] - 2024-05-27
4
3
  - Initial release
@@ -15,4 +14,10 @@
15
14
 
16
15
  ## [0.3.1] - 2024-08-10
17
16
  - Update docs
18
- - Change rails-mermaid_erd version dependency to at least 0.4.2
17
+ - Change rails-mermaid_erd version dependency to at least 0.4.2
18
+
19
+ ## [0.3.2] - 2024-08-10
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 CHANGED
@@ -9,5 +9,4 @@ group :development do
9
9
  gem "minitest"
10
10
  gem "rake"
11
11
  gem "rubocop"
12
- gem "sqlite3"
13
12
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails-mermaid_erd_markdown (0.3.1)
4
+ rails-mermaid_erd_markdown (0.4.0)
5
5
  rails (>= 5.2)
6
6
  rails-mermaid_erd (>= 0.4.2)
7
7
 
@@ -122,8 +122,12 @@ GEM
122
122
  nio4r (2.7.3)
123
123
  nokogiri (1.16.7-arm64-darwin)
124
124
  racc (~> 1.4)
125
- parallel (1.24.0)
126
- parser (3.3.1.0)
125
+ nokogiri (1.16.7-x86_64-darwin)
126
+ racc (~> 1.4)
127
+ nokogiri (1.16.7-x86_64-linux)
128
+ racc (~> 1.4)
129
+ parallel (1.26.1)
130
+ parser (3.3.4.2)
127
131
  ast (~> 2.4.1)
128
132
  racc
129
133
  psych (5.1.2)
@@ -175,26 +179,23 @@ GEM
175
179
  regexp_parser (2.9.2)
176
180
  reline (0.5.9)
177
181
  io-console (~> 0.5)
178
- rexml (3.2.8)
179
- strscan (>= 3.0.9)
180
- rubocop (1.64.0)
182
+ rexml (3.3.4)
183
+ strscan
184
+ rubocop (1.65.1)
181
185
  json (~> 2.3)
182
186
  language_server-protocol (>= 3.17.0)
183
187
  parallel (~> 1.10)
184
188
  parser (>= 3.3.0.2)
185
189
  rainbow (>= 2.2.2, < 4.0)
186
- regexp_parser (>= 1.8, < 3.0)
190
+ regexp_parser (>= 2.4, < 3.0)
187
191
  rexml (>= 3.2.5, < 4.0)
188
192
  rubocop-ast (>= 1.31.1, < 2.0)
189
193
  ruby-progressbar (~> 1.7)
190
194
  unicode-display_width (>= 2.4.0, < 3.0)
191
- rubocop-ast (1.31.3)
195
+ rubocop-ast (1.32.0)
192
196
  parser (>= 3.3.1.0)
193
197
  ruby-progressbar (1.13.0)
194
198
  securerandom (0.3.1)
195
- sqlite3 (1.7.3-arm64-darwin)
196
- sqlite3 (1.7.3-x86_64-darwin)
197
- sqlite3 (1.7.3-x86_64-linux)
198
199
  stringio (3.1.1)
199
200
  strscan (3.1.0)
200
201
  thor (1.3.1)
@@ -210,8 +211,8 @@ GEM
210
211
  zeitwerk (2.6.17)
211
212
 
212
213
  PLATFORMS
213
- arm64-darwin-23
214
- x86_64-darwin-22
214
+ arm64-darwin
215
+ x86_64-darwin
215
216
  x86_64-linux
216
217
 
217
218
  DEPENDENCIES
@@ -219,7 +220,6 @@ DEPENDENCIES
219
220
  rails-mermaid_erd_markdown!
220
221
  rake
221
222
  rubocop
222
- sqlite3
223
223
 
224
224
  BUNDLED WITH
225
- 2.3.3
225
+ 2.5.6
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 ERD
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
 
@@ -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 ||= RailsMermaidErd::Builder.model_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 }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MermaidErdMarkdown
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -54,7 +54,7 @@ module MockData
54
54
  }
55
55
  end
56
56
 
57
- def article_relation
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 profile_relation
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 comment_relation
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
- article_relation,
99
- profile_relation,
100
- comment_relation
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: [article_relation, profile_relation]
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: [article_relation, profile_relation]
12
+ Relations: [article_user_relation, profile_user_relation]
13
13
  }
14
14
  expected_profile = {
15
15
  Models: [profile_model, user_model],
16
- Relations: [profile_relation]
16
+ Relations: [profile_user_relation]
17
17
  }
18
18
  expected_article = {
19
19
  Models: [article_model, user_model, comment_model],
20
- Relations: [article_relation, comment_relation]
20
+ Relations: [article_user_relation, comment_article_relation]
21
21
  }
22
22
  expected_comment = {
23
23
  Models: [comment_model, article_model],
24
- Relations: [comment_relation]
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: [article_relation, profile_relation, comment_relation]
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: [profile_relation, article_relation]
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: [article_relation, comment_relation, profile_relation]
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: [comment_relation, article_relation]
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.3.1
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-10 00:00:00.000000000 Z
11
+ date: 2024-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails