Skip to content

Commit 0757160

Browse files
committed
Merge branch 'master' into pr-189
2 parents dba5755 + 2071305 commit 0757160

File tree

19 files changed

+81
-30
lines changed

19 files changed

+81
-30
lines changed

CHANGES.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
1.4.7
2+
-----
3+
* Fixed grouping of associations (#190)
4+
* Fixed issue with command line options (#198)
5+
* Fixed horizontally graph when vertical was wanted and viceversa (#183)
6+
7+
1.4.6
8+
-----
9+
* Revert auto-generation of diagrams added in #176 (#191)
10+
* Fix some Ruby warnings (#187)
11+
* Rescue from TypeError when loading target app (#185)
12+
113
1.4.5
214
-----
315

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Rails ERD - Generate Entity-Relationship Diagrams for Rails applications
66

77
The second goal of Rails ERD is to provide you with a tool to inspect your application's domain model. If you don't like the default output, it is very easy to use the API to build your own diagrams.
88

9-
Rails ERD was created specifically for Rails and works on versions 3.0-4.2. It uses Active Record's built-in reflection capabilities to figure out how your models are associated.
9+
Rails ERD was created specifically for Rails and works on versions 3.0-5.0. It uses Active Record's built-in reflection capabilities to figure out how your models are associated.
1010

1111

1212
Preview
@@ -62,6 +62,7 @@ exclude: null
6262
only: null
6363
only_recursion_depth: null
6464
prepend_primary: false
65+
cluster: false
6566
```
6667

6768

examples/erdconfig.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ exclude: null
1919
only: null
2020
only_recursion_depth: null
2121
prepend_primary: false
22+
cluster: false

lib/generators/erd/templates/auto_generate_diagram.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
33
# NOTE: to have a dev-mode tool do its thing in production.
44
if Rails.env.development?
5-
RailsERD::Engine.load_tasks
5+
Erd.load_tasks
66
end

lib/rails_erd.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require "active_support/ordered_options"
22
require "rails_erd/railtie" if defined? Rails
3-
require "rails_erd/engine" if defined? Rails
43
require "rails_erd/config"
54

65
# Welcome to the API documentation of Rails ERD. If you wish to extend or
@@ -53,7 +52,8 @@ def default_options
5352
:exclude, nil,
5453
:only, nil,
5554
:only_recursion_depth, nil,
56-
:prepend_primary, false
55+
:prepend_primary, false,
56+
:cluster, false,
5757
]
5858
end
5959
end

lib/rails_erd/cli.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969
desc "Ensure primary key is at start of attribute list"
7070
end
7171

72+
option :cluster do
73+
long "--cluster"
74+
desc "Display models in subgraphs based on their namespace."
75+
end
76+
7277
separator ""
7378
separator "Output options:"
7479

@@ -154,9 +159,14 @@ def start
154159

155160
def load_application
156161
$stderr.puts "Loading application in '#{File.basename(path)}'..."
157-
# TODO: Add support for different kinds of environment.
158-
require "#{path}/config/environment"
159-
Rails.application.eager_load!
162+
begin
163+
environment_path = "#{path}/config/environment.rb"
164+
require environment_path
165+
rescue ::LoadError
166+
puts "Please create a file in '#{environment_path}' that loads your application environment."
167+
raise
168+
end
169+
Rails.application.eager_load! if defined? Rails
160170
rescue TypeError
161171
end
162172

lib/rails_erd/config.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ def normalize_value(key, value)
5757
end
5858

5959
# <symbol>
60-
when :filetype, :notation, :orientation
60+
when :filetype, :notation
6161
value.to_sym
6262

6363
# [<string>]
6464
when :only, :exclude
6565
Array(value).join(",").split(",").map { |v| v.strip }
66+
6667
# true | false
67-
when :disconnected, :indirect, :inheritance, :markup, :polymorphism, :warn
68+
when :disconnected, :indirect, :inheritance, :markup, :polymorphism,
69+
:warn, :cluster
6870
!!value
6971

7072
# nil | <string>
71-
when :filename
73+
when :filename, :orientation
7274
value.nil? ? nil : value.to_s
7375

7476
# true | false | <string>

lib/rails_erd/diagram/graphviz.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def relationship_style(relationship)
183183
EDGE_ATTRIBUTES.each { |attribute, value| graph.edge[attribute] = value }
184184

185185
# Switch rank direction if we're creating a vertically oriented graph.
186-
graph[:rankdir] = :TB if options.orientation == :vertical
186+
graph[:rankdir] = (options.orientation == "vertical") ? :LR : :TB
187187

188188
# Title of the graph itself.
189189
graph[:label] = "#{title}\\n\\n" if title
@@ -210,7 +210,14 @@ def relationship_style(relationship)
210210
end
211211

212212
each_entity do |entity, attributes|
213-
draw_node entity.name, entity_options(entity, attributes)
213+
if options[:cluster] && entity.namespace
214+
cluster_name = "cluster_#{entity.namespace}"
215+
cluster = graph.get_graph(cluster_name) ||
216+
graph.add_graph(cluster_name, label: entity.namespace)
217+
draw_cluster_node cluster, entity.name, entity_options(entity, attributes)
218+
else
219+
draw_node entity.name, entity_options(entity, attributes)
220+
end
214221
end
215222

216223
each_specialization do |specialization|
@@ -233,15 +240,19 @@ def relationship_style(relationship)
233240
private
234241

235242
def node_exists?(name)
236-
!!graph.get_node(escape_name(name))
243+
!!graph.search_node(escape_name(name))
237244
end
238245

239246
def draw_node(name, options)
240247
graph.add_nodes escape_name(name), options
241248
end
242249

250+
def draw_cluster_node(cluster, name, options)
251+
cluster.add_nodes escape_name(name), options
252+
end
253+
243254
def draw_edge(from, to, options)
244-
graph.add_edges graph.get_node(escape_name(from)), graph.get_node(escape_name(to)), options if node_exists?(from) and node_exists?(to)
255+
graph.add_edges graph.search_node(escape_name(from)), graph.search_node(escape_name(to)), options if node_exists?(from) and node_exists?(to)
245256
end
246257

247258
def escape_name(name)

lib/rails_erd/domain/entity.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def children
9292
@children ||= domain.specializations_by_entity_name(name).map(&:specialized)
9393
end
9494

95+
def namespace
96+
name.scan(/(.*)::.*/).dig(0,0)
97+
end
98+
9599
def to_s # @private :nodoc:
96100
name
97101
end

lib/rails_erd/domain/relationship.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def from_associations(domain, associations) # @private :nodoc:
2121
private
2222

2323
def association_identity(association)
24-
identifier = association_identifier(association)
24+
identifier = association_identifier(association).to_s
2525
Set[identifier, association_owner(association), association_target(association)]
2626
end
2727

0 commit comments

Comments
 (0)