activerecord_uml 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14ef2902767bb5de3b65b387a336ab4f3ebe234dea52cf6c8b1d3cb756818fdc
4
- data.tar.gz: 760d9f81fda80c254be2de0f207474555f93ae470260b9dc6644940981b0e720
3
+ metadata.gz: 524e8fd8aae920263ae3656b95dfc3212351f833308e464433e8d30721fa3be3
4
+ data.tar.gz: ab42d8b193be4a5cfd69757520234e5de0f0c4ee1b2d27653644ce93ee0b1993
5
5
  SHA512:
6
- metadata.gz: 685b19398a365c8b47905bfdf6aba021fc61cbfaa4ecf022f6777a05dc09341b404816f3ba308edb729651d76a37c16970087de7072021591dbb490a4d3e2d9e
7
- data.tar.gz: 4c1079d76751897c77ddfae33ed10708e675e0726871d3a34ffd57a8699ce36609a9fa5e2a56c2f906e140d780330fb3f7fa5e530da69ceb5d21bde66022e6a0
6
+ metadata.gz: a132b611158a08dc74a7999795289ece5a52e251375e446e8906cf162a92753395a2105e535a387a493c63e2049d373d34183283788b28c85c37de6abf77ea90
7
+ data.tar.gz: 32f612150542eba6e8de91ce0b95fe961be3dc6f955322d4fabd96d2fd724790b386fc0fe3486789d1eae8c2dcb39c1290d2ccd22251ea6a6c569a874efc436d
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| r.belongs_to?(ARGV) }
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,20 +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}#{label_for a}"
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
34
  if a.is_a? ActiveRecord::Reflection::ThroughReflection
34
35
  if a.source_reflection
35
36
  # If a source association is specified, the class name of the source association is displayed.
36
- "#{@class_name} *--* #{a.source_reflection.class_name}#{label_for a}"
37
+ Relation.new(@class_name, "*--*", a.source_reflection.class_name, a)
37
38
  else
38
- "#{@class_name} *--* #{a.class_name}#{label_for a}"
39
+ Relation.new(@class_name, "*--*", a.class_name, a)
39
40
  end
40
41
  else
41
- "#{@class_name} --* #{a.class_name}#{label_for a}"
42
+ Relation.new(@class_name, "--*", a.class_name, a)
42
43
  end
43
44
  end).concat(@class_name.reflect_on_all_associations(:has_one).map do |a|
44
- "#{@class_name} --* #{a.class_name}#{label_for a}"
45
+ Relation.new(@class_name, "--*", a.class_name, a)
45
46
  end)
46
47
  end
47
48
 
@@ -65,9 +66,5 @@ EOF
65
66
  [m.to_s, method_parameters.join(", ")]
66
67
  end
67
68
  end
68
-
69
- def label_for(association)
70
- association.class_name != association.name.to_s.classify ? " : #{association.name.to_s.classify}" : ""
71
- end
72
69
  end
73
70
  end
@@ -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.11.0"
4
+ VERSION = "0.12.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.11.0
4
+ version: 0.12.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-28 00:00:00.000000000 Z
11
+ date: 2021-07-30 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: []