activerecord_uml 0.9.0 → 0.13.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: 1b7b698036a7de92dbddb185bd926ba6b217a81e6a327c640b1b32d42f307e2b
4
- data.tar.gz: 3fe7ceea6496984fa9a6ceb793ba25eb364d996d071741c056c8d45373c95b2b
3
+ metadata.gz: 2cc6a981ab5f550073e505fb2192a116251d261699b0ebea985fee66644daddf
4
+ data.tar.gz: e20fd64c002bb27f63877bcfb5312033b0f3976d442234f181ea84063169415a
5
5
  SHA512:
6
- metadata.gz: b98c294a19a863046f62c106551361fd2966e027204c6be380d6e987577d21992246476d693d68484d267d093dd3d33aa653fd738f8e402c41d0b19ac6af2545
7
- data.tar.gz: 7d43a94fd8ba024423521eb085494e1ff98266b107c3d361f01e95f53883f61b2620a1451c7705f315accc6db0f204dc8f3e5ef763855a4d17a98bfae1a68188
6
+ metadata.gz: 92e36b86b5fa17bf477d1f42f14d003e886fc2c9690e81d5131f3dafdc0a0e4c6ddd93c975ce23087af6ef5567e3f8267e889d57220f8def355392a566f9e446
7
+ data.tar.gz: 48a54fdf7c0ba6731ed425faf868c2eddc44a1406bf305d58eabd00cebcf5bd4ef66acc1ebbfb875e15a540c7171f3fff3c2aa92ad8a8a739ebb4a372150b951
data/README.md CHANGED
@@ -10,17 +10,7 @@ ActiverecordUml draws class diagrams of selected models to help to recognize the
10
10
 
11
11
  ## Installation
12
12
 
13
- Add this line to your application's Gemfile:
14
-
15
- ```ruby
16
- gem 'activerecord_uml'
17
- ```
18
-
19
- And then execute:
20
-
21
- $ bundle install
22
-
23
- Or install it yourself as:
13
+ install it yourself as:
24
14
 
25
15
  $ gem install activerecord_uml
26
16
 
@@ -35,7 +25,13 @@ activerecord_uml User Book Review
35
25
  Execute the activerecord_uml command with name of model classes.
36
26
  Then the activerecord_uml outputs HTML text includes class diagrams of specified model classes.
37
27
 
38
- For MacOs, I recommend to use the activerecord_uml with [browser](https://gist.github.com/defunkt/318247) command.
28
+ For macOS, You can see the diagram:
29
+ ```
30
+ activerecord_uml User Book Review > temp.html
31
+ open temp.html
32
+ ```
33
+
34
+ I recommend to use the activerecord_uml with [browser](https://gist.github.com/defunkt/318247) command.
39
35
  For example:
40
36
 
41
37
  Install browser with Homebrew.
@@ -52,6 +48,17 @@ activerecord_uml User | browser
52
48
 
53
49
  Open the class diagrams with the browser immediately.
54
50
 
51
+ ### activerecord_relations
52
+
53
+ If you want to see the complex relationships between classes, you can use the activecord_relations command.
54
+
55
+ ```
56
+ activerecord_relations User Book Review
57
+ ```
58
+
59
+ This command will only show the relationships between the specified classes.
60
+
61
+
55
62
  ## Development
56
63
 
57
64
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake ` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,8 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ activerecord_uml = File.join __dir__, "../lib/activerecord_uml"
4
+ ruby_script = "require \"#{activerecord_uml}\"; ActiverecordUml.draw true"
5
+ rails = File.join Dir.pwd, "bin/rails"
6
+ rails_runner_command = "echo '#{ruby_script}' | #{rails} runner - #{ARGV.join " "}"
7
+
8
+ system rails_runner_command
@@ -4,7 +4,7 @@ require_relative "activerecord_uml/version"
4
4
  require_relative "activerecord_uml/diagram_drawer"
5
5
 
6
6
  module ActiverecordUml
7
- def self.draw
7
+ def self.draw(relation_only = false)
8
8
  html = <<EOF
9
9
  <html>
10
10
  <body>
@@ -28,7 +28,11 @@ EOF
28
28
 
29
29
  html_template = ERB.new html, nil, "<>"
30
30
  classes = ARGV.map { |model_name| DiagramDrawer.new(model_name) }
31
- puts html_template.result_with_hash class_diagrams: classes.map { |c| c.class_diagram },
32
- relations: classes.map { |c| c.relations }.flatten.uniq
31
+ puts html_template.result_with_hash class_diagrams: relation_only ? [] : classes.map { |c| c.class_diagram },
32
+ relations: classes.map { |c| c.relations }
33
+ .flatten
34
+ .select { |r| relation_only ? r.belongs_to?(ARGV) : true }
35
+ .map(&:to_s)
36
+ .uniq
33
37
  end
34
38
  end
@@ -1,4 +1,5 @@
1
1
  require "erb"
2
+ require_relative "./relation.rb"
2
3
 
3
4
  module ActiverecordUml
4
5
  class DiagramDrawer
@@ -28,11 +29,20 @@ EOF
28
29
 
29
30
  def relations
30
31
  @class_name.reflect_on_all_associations(:belongs_to).map do |a|
31
- "#{a.class_name} --* #{@class_name}"
32
+ Relation.new(a.class_name, "--*", @class_name, a)
32
33
  end.concat(@class_name.reflect_on_all_associations(:has_many).map do |a|
33
- "#{@class_name} --* #{a.class_name}"
34
+ if a.is_a? ActiveRecord::Reflection::ThroughReflection
35
+ if a.source_reflection
36
+ # If a source association is specified, the class name of the source association is displayed.
37
+ Relation.new(@class_name, "*--*", a.source_reflection.class_name, a)
38
+ else
39
+ Relation.new(@class_name, "*--*", a.class_name, a)
40
+ end
41
+ else
42
+ Relation.new(@class_name, "--*", a.class_name, a)
43
+ end
34
44
  end).concat(@class_name.reflect_on_all_associations(:has_one).map do |a|
35
- "#{@class_name} --* #{a.class_name}"
45
+ Relation.new(@class_name, "--*", a.class_name, a)
36
46
  end)
37
47
  end
38
48
 
@@ -0,0 +1,24 @@
1
+ module ActiverecordUml
2
+ class Relation
3
+ def initialize(left_name, multiplicity, right_name, association)
4
+ @left_name = left_name
5
+ @right_name = right_name
6
+ @association = association
7
+ @multiplicity = multiplicity
8
+ end
9
+
10
+ def belongs_to?(class_names)
11
+ class_names.include?(@left_name.to_s) && class_names.include?(@right_name)
12
+ end
13
+
14
+ def to_s
15
+ "#{@left_name} #{@multiplicity} #{@right_name}#{label}"
16
+ end
17
+
18
+ private
19
+
20
+ def label
21
+ @association.class_name != @association.name.to_s.classify ? " : #{@association.name.to_s.classify}" : ""
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiverecordUml
4
- VERSION = "0.9.0"
4
+ VERSION = "0.13.0"
5
5
  end
metadata CHANGED
@@ -1,20 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_uml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - shigeru.nakajima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-21 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Generate UML class diagram for Mermaid.js from ActiveRecord instances
14
14
  by Rails runner.
15
15
  email:
16
16
  - shigeru.nakajima@gmail.com
17
17
  executables:
18
+ - activerecord_relations
18
19
  - activerecord_uml
19
20
  extensions: []
20
21
  extra_rdoc_files: []
@@ -26,9 +27,11 @@ files:
26
27
  - activerecord_uml.gemspec
27
28
  - bin/console
28
29
  - bin/setup
30
+ - exe/activerecord_relations
29
31
  - exe/activerecord_uml
30
32
  - lib/activerecord_uml.rb
31
33
  - lib/activerecord_uml/diagram_drawer.rb
34
+ - lib/activerecord_uml/relation.rb
32
35
  - lib/activerecord_uml/version.rb
33
36
  homepage: https://github.com/ledsun/activerecord_uml
34
37
  licenses: []