rails-mermaid_erd_markdown 0.1.0 → 0.3.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.
@@ -0,0 +1,105 @@
1
+ module MockData
2
+ module Models
3
+ def user_model
4
+ {
5
+ TableName: "users", ModelName: "User", IsModelExist: true,
6
+ Columns: [
7
+ { name: "id", type: :integer, key: "PK", comment: nil },
8
+ { name: "name", type: :string, key: "", comment: nil },
9
+ { name: "email", type: :string, key: "", comment: nil },
10
+ { name: "created_at", type: :datetime, key: "", comment: nil },
11
+ { name: "updated_at", type: :datetime, key: "", comment: nil }
12
+ ]
13
+ }
14
+ end
15
+
16
+ def profile_model
17
+ {
18
+ TableName: "profiles", ModelName: "Profile", IsModelExist: true,
19
+ Columns: [
20
+ { name: "id", type: :integer, key: "PK", comment: nil },
21
+ { name: "bio", type: :text, key: "", comment: nil },
22
+ { name: "user_id", type: :integer, key: "FK", comment: nil },
23
+ { name: "created_at", type: :datetime, key: "", comment: nil },
24
+ { name: "updated_at", type: :datetime, key: "", comment: nil }
25
+ ]
26
+ }
27
+ end
28
+
29
+ def article_model
30
+ {
31
+ TableName: "articles", ModelName: "Article", IsModelExist: true,
32
+ Columns: [
33
+ { name: "id", type: :integer, key: "PK", comment: nil },
34
+ { name: "title", type: :string, key: "", comment: nil },
35
+ { name: "content", type: :text, key: "", comment: nil },
36
+ { name: "user_id", type: :integer, key: "FK", comment: nil },
37
+ { name: "created_at", type: :datetime, key: "", comment: nil },
38
+ { name: "updated_at", type: :datetime, key: "", comment: nil }
39
+ ]
40
+ }
41
+ end
42
+
43
+ def comment_model
44
+ {
45
+ TableName: "comments", ModelName: "Comment", IsModelExist: true,
46
+ Columns: [
47
+ { name: "id", type: :integer, key: "PK", comment: nil },
48
+ { name: "commenter", type: :string, key: "", comment: nil },
49
+ { name: "body", type: :text, key: "", comment: nil },
50
+ { name: "article_id", type: :integer, key: "FK", comment: nil },
51
+ { name: "created_at", type: :datetime, key: "", comment: nil },
52
+ { name: "updated_at", type: :datetime, key: "", comment: nil }
53
+ ]
54
+ }
55
+ end
56
+
57
+ def article_relation
58
+ {
59
+ LeftModelName: "Article",
60
+ LeftValue: "}o",
61
+ Line: "--",
62
+ RightModelName: "User",
63
+ RightValue: "||",
64
+ Comment: "BT:user"
65
+ }
66
+ end
67
+
68
+ def profile_relation
69
+ {
70
+ LeftModelName: "Profile",
71
+ LeftValue: "}o",
72
+ Line: "--",
73
+ RightModelName: "User",
74
+ RightValue: "||",
75
+ Comment: "BT:user"
76
+ }
77
+ end
78
+
79
+ def comment_relation
80
+ {
81
+ LeftModelName: "Comment",
82
+ LeftValue: "}o",
83
+ Line: "--",
84
+ RightModelName: "Article",
85
+ RightValue: "||",
86
+ Comment: "BT:article"
87
+ }
88
+ end
89
+
90
+ def stubbed_model_data
91
+ {
92
+ Models: [
93
+ user_model,
94
+ profile_model,
95
+ article_model,
96
+ comment_model
97
+ ], Relations: [
98
+ article_relation,
99
+ profile_relation,
100
+ comment_relation
101
+ ]
102
+ }
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "rails-mermaid_erd_markdown"
5
+ require "rails-mermaid_erd_markdown/configuration"
6
+ require "rails-mermaid_erd_markdown/generator"
7
+ require "rails-mermaid_erd_markdown/markdown_document"
8
+ require "rails-mermaid_erd_markdown/source_data"
9
+
10
+ require "minitest/autorun"
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../mock_data/models"
4
+ require "test_helper"
5
+
6
+ class MermaidErdMarkdown::GeneratorTest < Minitest::Test
7
+ include MockData::Models
8
+
9
+ def test_index_markdown
10
+ markdown_file_path = File.expand_path(
11
+ "../../example_output/mock_ERD_index.md", __dir__
12
+ )
13
+ mock_markdown = File.read(markdown_file_path)
14
+
15
+ files = {
16
+ "User" => "User.md",
17
+ "Profile" => "Profile.md",
18
+ "Article" => "Article.md",
19
+ "Comment" => "Comment.md"
20
+ }
21
+
22
+ result = MermaidErdMarkdown::Generator.new.index_markdown(files)
23
+
24
+ assert_equal mock_markdown, result
25
+ end
26
+
27
+ def test_model_markdown
28
+ markdown_file_path = File.expand_path(
29
+ "../../example_output/mock_ERD_model.md", __dir__
30
+ )
31
+ mock_markdown = File.read(markdown_file_path)
32
+
33
+ source = {
34
+ Models: [user_model, article_model, profile_model],
35
+ Relations: [article_relation, profile_relation]
36
+ }
37
+
38
+ result = MermaidErdMarkdown::Generator.new.model_markdown(source)
39
+
40
+ assert_equal mock_markdown, result
41
+ end
42
+
43
+ def test_mermaid_markdown
44
+ markdown_file_path =
45
+ File.expand_path("../../example_output/mock_ERD.md", __dir__)
46
+ mock_markdown = File.read(markdown_file_path)
47
+
48
+ result = MermaidErdMarkdown::Generator.new.mermaid_markdown(
49
+ stubbed_model_data
50
+ )
51
+
52
+ assert_equal mock_markdown, result
53
+ end
54
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class MermaidErdMarkdown::MarkdownDocumentTest < Minitest::Test
6
+ def test_generate
7
+ markdown = MermaidErdMarkdown::MarkdownDocument.create do
8
+ add(header("Header"))
9
+ add(subheader("Subheader"))
10
+ add(list_item("List item"))
11
+ add(link("Link", "https://example.com"))
12
+ add("")
13
+ end
14
+
15
+ assert_equal <<~MARKDOWN, markdown
16
+ # Header
17
+
18
+ ## Subheader
19
+
20
+ - List item
21
+ [Link](https://example.com)
22
+ MARKDOWN
23
+ end
24
+
25
+ def test_erd
26
+ model = {
27
+ TableName: "table",
28
+ ModelName: "Table",
29
+ IsModelExist: true,
30
+ Columns: [{
31
+ name: "name",
32
+ type: "type",
33
+ key: "key",
34
+ comment: "comment"
35
+ }]
36
+ }
37
+ relation = {
38
+ LeftModelName: "left_model",
39
+ LeftValue: "left_value",
40
+ Line: "--",
41
+ RightValue: "right_value",
42
+ RightModelName: "right_model",
43
+ Comment: "comment"
44
+ }
45
+
46
+ markdown = MermaidErdMarkdown::MarkdownDocument.create do
47
+ erd do
48
+ add(
49
+ erd_table(model[:TableName], model[:ModelName]) do
50
+ erd_table_column(model[:Columns].first)
51
+ end
52
+ )
53
+ add(
54
+ erd_relation(relation)
55
+ )
56
+ end
57
+ add("")
58
+ end
59
+
60
+ assert_equal <<~MARKDOWN, markdown
61
+ ```mermaid
62
+ erDiagram
63
+ %% --------------------------------------------------------
64
+ %% Entity-Relationship Diagram
65
+ %% --------------------------------------------------------
66
+
67
+ %% table name: table
68
+ Table{
69
+ type name key
70
+ }
71
+
72
+ left_model left_value--right_value right_model : "comment"
73
+ ```
74
+ MARKDOWN
75
+ end
76
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../mock_data/models"
4
+ require "test_helper"
5
+
6
+ class MermaidErdMarkdown::SourceDataTest < Minitest::Test
7
+ include MockData::Models
8
+
9
+ def test_split_output
10
+ expected_user = {
11
+ Models: [user_model, article_model, profile_model],
12
+ Relations: [article_relation, profile_relation]
13
+ }
14
+ expected_profile = {
15
+ Models: [profile_model, user_model],
16
+ Relations: [profile_relation]
17
+ }
18
+ expected_article = {
19
+ Models: [article_model, user_model, comment_model],
20
+ Relations: [article_relation, comment_relation]
21
+ }
22
+ expected_comment = {
23
+ Models: [comment_model, article_model],
24
+ Relations: [comment_relation]
25
+ }
26
+ expected = [
27
+ expected_user,
28
+ expected_profile,
29
+ expected_article,
30
+ expected_comment
31
+ ]
32
+
33
+ RailsMermaidErd::Builder.stub :model_data, stubbed_model_data do
34
+ result = MermaidErdMarkdown::SourceData.new.split_output
35
+
36
+ assert_equal expected, result
37
+ end
38
+ end
39
+
40
+ def test_split_output_with_depth
41
+ expected_user = {
42
+ Models: [user_model, article_model, profile_model, comment_model],
43
+ Relations: [article_relation, profile_relation, comment_relation]
44
+ }
45
+ expected_profile = {
46
+ Models: [profile_model, user_model, article_model],
47
+ Relations: [profile_relation, article_relation]
48
+ }
49
+ expected_article = {
50
+ Models: [article_model, user_model, comment_model, profile_model],
51
+ Relations: [article_relation, comment_relation, profile_relation]
52
+ }
53
+ expected_comment = {
54
+ Models: [comment_model, article_model, user_model],
55
+ Relations: [comment_relation, article_relation]
56
+ }
57
+ expected = [
58
+ expected_user,
59
+ expected_profile,
60
+ expected_article,
61
+ expected_comment
62
+ ]
63
+
64
+ RailsMermaidErd::Builder.stub :model_data, stubbed_model_data do
65
+ result = MermaidErdMarkdown::SourceData.new.split_output(2)
66
+
67
+ assert_equal expected, result
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class MermaidErdMarkdownTest < Minitest::Test
6
+ def test_that_it_has_a_version_number
7
+ refute_nil MermaidErdMarkdown::VERSION
8
+ end
9
+ 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.1.0
4
+ version: 0.3.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-05-28 00:00:00.000000000 Z
11
+ date: 2024-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails-mermaid_erd
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.2
27
41
  description:
28
42
  email:
29
43
  - 89326566+humzahkiani@users.noreply.github.com
@@ -31,12 +45,40 @@ executables: []
31
45
  extensions: []
32
46
  extra_rdoc_files: []
33
47
  files:
48
+ - ".github/CODEOWNERS.md"
49
+ - ".github/workflows/CI.yml"
50
+ - ".github/workflows/codeql.yml"
51
+ - ".gitignore"
52
+ - ".rubocop.yml"
53
+ - ".ruby-version"
54
+ - CHANGELOG.md
55
+ - CODE_OF_CONDUCT.md
56
+ - Gemfile
57
+ - Gemfile.lock
58
+ - LICENSE.txt
34
59
  - README.md
35
60
  - Rakefile
61
+ - bin/console
62
+ - bin/rubocop
63
+ - bin/setup
36
64
  - docs/examples/erd.yml
37
65
  - lib/rails-mermaid_erd_markdown.rb
38
66
  - lib/rails-mermaid_erd_markdown/configuration.rb
67
+ - lib/rails-mermaid_erd_markdown/generator.rb
68
+ - lib/rails-mermaid_erd_markdown/markdown_document.rb
69
+ - lib/rails-mermaid_erd_markdown/source_data.rb
39
70
  - lib/rails-mermaid_erd_markdown/version.rb
71
+ - rails-mermaid_erd_markdown.gemspec
72
+ - sig/rails/mermaid_erd_markdown.rbs
73
+ - test/example_output/mock_ERD.md
74
+ - test/example_output/mock_ERD_index.md
75
+ - test/example_output/mock_ERD_model.md
76
+ - test/mock_data/models.rb
77
+ - test/test_helper.rb
78
+ - test/test_rails/rails-mermaid_erd_markdown/test_generator.rb
79
+ - test/test_rails/rails-mermaid_erd_markdown/test_markdown_document.rb
80
+ - test/test_rails/rails-mermaid_erd_markdown/test_source_data.rb
81
+ - test/test_rails/test_rails-mermaid_erd_markdown.rb
40
82
  homepage: https://github.com/humzahkiani/rails-mermaid_erd_markdown
41
83
  licenses:
42
84
  - MIT
@@ -44,6 +86,8 @@ metadata:
44
86
  homepage_uri: https://github.com/humzahkiani/rails-mermaid_erd_markdown
45
87
  source_code_uri: https://github.com/humzahkiani/rails-mermaid_erd_markdown
46
88
  changelog_uri: https://github.com/humzahkiani/rails-mermaid_erd_markdown/blob/main/CHANGELOG.md
89
+ github_repo: ssh://github.com/humzahkiani/rails-mermaid_erd_markdown
90
+ rubygems_mfa_required: 'true'
47
91
  post_install_message:
48
92
  rdoc_options: []
49
93
  require_paths: