rails-erd 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8d99cbfb786b715088ed547c22acac6150d65109
4
+ data.tar.gz: 6b7631aea348df78d4d7a6add5c9b590c5c4f2fb
5
+ SHA512:
6
+ metadata.gz: 912040089037e2eae86864507ee3efd5d1f51825b256e7464204ebaacb1bf5af0a89785f0f4948de093a2b5797bdd119fa3c4a9fcc1e7ce158713179f12c2140
7
+ data.tar.gz: adf9512f873f3b19632a0e1cf165e764395cda87b03f6fcb1654a58c1d925bc26dd6eae3050450be4d855a948c438a47d2ee5f1eec0497e4c727dab163cd0534
data/README.md CHANGED
@@ -1,17 +1,11 @@
1
1
  Rails ERD - Generate Entity-Relationship Diagrams for Rails applications
2
2
  ========================================================================
3
3
 
4
- [Rails ERD](http://rails-erd.rubyforge.org/) is a Rails plugin that allows
5
- you to easily generate a diagram based on your Active Record models. The
6
- diagram gives an overview of how your models are related. Having a diagram
7
- that describes your models is perfect documentation for your application.
4
+ [Rails ERD](http://voormedia.github.io/rails-erd/) is a Rails plugin that allows you to easily generate a diagram based on your Active Record models. The diagram gives an overview of how your models are related. Having a diagram that describes your models is perfect documentation for your application.
8
5
 
9
- The second goal of Rails ERD is to provide you with a tool to inspect your
10
- application's domain model. If you don't like the default output, it is very
11
- easy to use the API to build your own diagrams.
6
+ 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.
12
7
 
13
- Rails ERD was created specifically for Rails 3. It uses Active Record's
14
- built-in reflection capabilities to figure out how your models are associated.
8
+ Rails ERD was created specifically for Rails 3. It uses Active Record's built-in reflection capabilities to figure out how your models are associated.
15
9
 
16
10
 
17
11
  Preview
@@ -19,31 +13,53 @@ Preview
19
13
 
20
14
  Here's an example entity-relationship diagram that was generated by Rails ERD:
21
15
 
22
- ![Entity-Relationship Diagram](http://rails-erd.rubyforge.org/images/entity-relationship-diagram.png)
16
+ ![Entity-Relationship Diagram](http://voormedia.github.io/rails-erd/images/entity-relationship-diagram.png)
23
17
 
24
- Browse the [gallery](http://rails-erd.rubyforge.org/gallery.html) for more
25
- example diagrams.
18
+ Browse the [gallery](http://voormedia.github.io/rails-erd/gallery.html) for more example diagrams.
26
19
 
27
20
 
28
21
  Getting started
29
22
  ---------------
30
23
 
31
- See the [installation instructions](http://rails-erd.rubyforge.org/install.html)
32
- for a complete description of how to install Rails ERD. Here's a summary:
24
+ See the [installation instructions](http://voormedia.github.io/rails-erd/install.html) for a complete description of how to install Rails ERD. Here's a summary:
33
25
 
34
- * Install Graphviz 2.22+ ([how?](http://rails-erd.rubyforge.org/install.html))
26
+ * Install Graphviz 2.22+ ([how?](http://voormedia.github.io/rails-erd/install.html))
35
27
 
36
28
  * Add <tt>gem "rails-erd"</tt> to your application's Gemfile
37
29
 
38
30
  * Run <tt>bundle exec erd</tt>
39
31
 
32
+ ### Configuration
33
+
34
+ Rails ERD has the ability to be configured via the command line or through the use of a YAML file with configuration options set. It will look for this file first at `~/.erdconfig` and then `./.erdconfig` (which will override any settings in `~/.erdconfig`). The format of the file is as follows (shown here with the default settings used if no `.erdconfig` is found):
35
+
36
+ ```
37
+ attributes:
38
+ - content
39
+ - foreign_key
40
+ - inheritance
41
+ disconnected: true
42
+ filename: erd
43
+ filetype: pdf
44
+ indirect: true
45
+ inheritance: false
46
+ markup: true
47
+ notation: simple
48
+ orientation: horizontal
49
+ polymorphism: false
50
+ warn: true
51
+ title: sample title
52
+ exclude: null
53
+ only:
54
+ ```
55
+
40
56
 
41
57
  Learn more
42
58
  ----------
43
59
 
44
- More information can be found on [Rails ERD's project homepage](http://rails-erd.rubyforge.org/).
60
+ More information can be found on [Rails ERD's project homepage](http://voormedia.github.io/rails-erd/).
45
61
 
46
- If you wish to extend or customise Rails ERD, take a look at the [API documentation](http://rails-erd.rubyforge.org/doc/).
62
+ If you wish to extend or customise Rails ERD, take a look at the [API documentation](http://rubydoc.info/github/voormedia/rails-erd/frames).
47
63
 
48
64
 
49
65
  About Rails ERD
@@ -51,7 +67,7 @@ About Rails ERD
51
67
 
52
68
  Rails ERD was created by Rolf Timmermans (r.timmermans *at* voormedia.com)
53
69
 
54
- Copyright 2010-2013 Voormedia - [www.voormedia.com](http://www.voormedia.com/)
70
+ Copyright 2010-2014 Voormedia - [www.voormedia.com](http://www.voormedia.com/)
55
71
 
56
72
 
57
73
  License
data/lib/rails_erd.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "active_support/ordered_options"
2
2
  require "rails_erd/railtie" if defined? Rails
3
+ require "rails_erd/config"
3
4
 
4
5
  # Welcome to the API documentation of Rails ERD. If you wish to extend or
5
6
  # customise the output that is generated by Rails ERD, you have come to the
@@ -32,6 +33,25 @@ module RailsERD
32
33
  # Access to default options. Any instance of RailsERD::Domain and
33
34
  # RailsERD::Diagram will use these options unless overridden.
34
35
  attr_accessor :options
36
+
37
+ def default_options
38
+ ActiveSupport::OrderedOptions[
39
+ :attributes, :content,
40
+ :disconnected, true,
41
+ :filename, "erd",
42
+ :filetype, :pdf,
43
+ :indirect, true,
44
+ :inheritance, false,
45
+ :markup, true,
46
+ :notation, :simple,
47
+ :orientation, :horizontal,
48
+ :polymorphism, false,
49
+ :warn, true,
50
+ :title, true,
51
+ :exclude, nil,
52
+ :only, nil
53
+ ]
54
+ end
35
55
  end
36
56
 
37
57
  module Inspectable # @private :nodoc:
@@ -47,20 +67,5 @@ module RailsERD
47
67
  end
48
68
  end
49
69
 
50
- self.options = ActiveSupport::OrderedOptions[
51
- :attributes, :content,
52
- :disconnected, true,
53
- :filename, "erd",
54
- :filetype, :pdf,
55
- :indirect, true,
56
- :inheritance, false,
57
- :markup, true,
58
- :notation, :simple,
59
- :orientation, :horizontal,
60
- :polymorphism, false,
61
- :warn, true,
62
- :title, true,
63
- :exclude, nil,
64
- :only, nil
65
- ]
70
+ self.options = default_options.merge(Config.load)
66
71
  end
@@ -0,0 +1,92 @@
1
+ module RailsERD
2
+ class Config
3
+ USER_WIDE_CONFIG_FILE = File.expand_path(".erdconfig", ENV["HOME"])
4
+ CURRENT_CONFIG_FILE = File.expand_path(".erdconfig", Dir.pwd)
5
+
6
+ attr_reader :options
7
+
8
+ def self.load
9
+ new.load
10
+ end
11
+
12
+ def initialize
13
+ @options = {}
14
+ end
15
+
16
+ def load
17
+ load_file(USER_WIDE_CONFIG_FILE)
18
+ load_file(CURRENT_CONFIG_FILE)
19
+
20
+ @options
21
+ end
22
+
23
+ def self.font_names_based_on_os
24
+ if use_os_x_fonts?
25
+ { normal: "ArialMT",
26
+ bold: "Arial BoldMT",
27
+ italic: "Arail ItalicMT" }
28
+ else
29
+ { normal: "Arial",
30
+ bold: "Arial Bold",
31
+ italic: "Arail Italic" }
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def load_file(path)
38
+ if File.exists?(path)
39
+ YAML.load_file(path).each do |key, value|
40
+ key = key.to_sym
41
+ @options[key] = normalize_value(key, value)
42
+ end
43
+ end
44
+ end
45
+
46
+ def normalize_value(key, value)
47
+ case key
48
+ # <symbol>[,<symbol>,...] | false
49
+ when :attributes
50
+ if value == false
51
+ return value
52
+ else
53
+ # Comma separated string and strings in array are OK.
54
+ Array(value).join(",").split(",").map { |v| v.strip.to_sym }
55
+ end
56
+
57
+ # <symbol>
58
+ when :filetype, :notation, :orientation
59
+ value.to_sym
60
+
61
+ # true | false
62
+ when :disconnected, :indirect, :inheritance, :markup, :polymorphism, :warn
63
+ !!value
64
+
65
+ # nil | <string>
66
+ when :filename, :only, :exclude
67
+ value.nil? ? nil : value.to_s
68
+
69
+ # true | false | <string>
70
+ when :title
71
+ value.is_a?(String) ? value : !!value
72
+
73
+ else
74
+ value
75
+ end
76
+ end
77
+
78
+ def self.use_os_x_fonts?
79
+ host = RbConfig::CONFIG['host_os']
80
+
81
+ if host.include? "darwin"
82
+ darwin_version_array = host.split("darwin").last.split(".").map(&:to_i)
83
+
84
+ if darwin_version_array[0] == 12 and darwin_version_array[1] >= 5
85
+ return true
86
+ end
87
+ end
88
+
89
+ false
90
+ end
91
+ end
92
+ end
@@ -47,6 +47,8 @@ module RailsERD
47
47
 
48
48
  NODE_WIDTH = 130 # @private :nodoc:
49
49
 
50
+ FONTS = Config.font_names_based_on_os
51
+
50
52
  # Default graph attributes.
51
53
  GRAPH_ATTRIBUTES = {
52
54
  :rankdir => :LR,
@@ -57,21 +59,21 @@ module RailsERD
57
59
  :concentrate => true,
58
60
  :labelloc => :t,
59
61
  :fontsize => 13,
60
- :fontname => "Arial Bold"
62
+ :fontname => FONTS[:bold]
61
63
  }
62
64
 
63
65
  # Default node attributes.
64
66
  NODE_ATTRIBUTES = {
65
67
  :shape => "Mrecord",
66
68
  :fontsize => 10,
67
- :fontname => "Arial",
69
+ :fontname => FONTS[:normal],
68
70
  :margin => "0.07,0.05",
69
71
  :penwidth => 1.0
70
72
  }
71
73
 
72
74
  # Default edge attributes.
73
75
  EDGE_ATTRIBUTES = {
74
- :fontname => "Arial",
76
+ :fontname => FONTS[:normal],
75
77
  :fontsize => 8,
76
78
  :dir => :both,
77
79
  :arrowsize => 0.9,
@@ -1,14 +1,14 @@
1
1
  <% if options.orientation == :vertical %>{<% end %>
2
2
  <table border="0" align="center" cellspacing="0.5" cellpadding="0" width="<%= NODE_WIDTH + 4 %>">
3
- <tr><td align="center" valign="bottom" width="<%= NODE_WIDTH %>"><font face="Arial Bold" point-size="11"><%= entity.name %></font></td></tr>
3
+ <tr><td align="center" valign="bottom" width="<%= NODE_WIDTH %>"><font face="<%= FONTS[:bold] %>" point-size="11"><%= entity.name %></font></td></tr>
4
4
  </table>
5
5
  <% if attributes.any? %>
6
6
  |
7
7
  <table border="0" align="left" cellspacing="2" cellpadding="0" width="<%= NODE_WIDTH + 4 %>">
8
8
  <% attributes.each do |attribute| %>
9
- <tr><td align="left" width="<%= NODE_WIDTH %>" port="<%= attribute %>"><%= attribute %> <font face="Arial Italic" color="grey60"><%= attribute.type_description %></font></td></tr>
9
+ <tr><td align="left" width="<%= NODE_WIDTH %>" port="<%= attribute %>"><%= attribute %> <font face="<%= FONTS[:italic] %>" color="grey60"><%= attribute.type_description %></font></td></tr>
10
10
  <% end %>
11
11
  </table>
12
12
  <% else %>
13
13
  <% end %>
14
- <% if options.orientation == :vertical %>}<% end %>
14
+ <% if options.orientation == :vertical %>}<% end %>
@@ -1,4 +1,4 @@
1
1
  module RailsERD
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  BANNER = "RailsERD #{VERSION}"
4
4
  end
@@ -0,0 +1,3 @@
1
+ attributes:
2
+ - primary_key
3
+
@@ -0,0 +1,18 @@
1
+ attributes:
2
+ - content
3
+ - foreign_key
4
+ - inheritance
5
+ disconnected: true
6
+ filename: erd
7
+ filetype: pdf
8
+ indirect: true
9
+ inheritance: false
10
+ markup: true
11
+ notation: simple
12
+ orientation: horizontal
13
+ polymorphism: false
14
+ warn: true
15
+ title: sample title
16
+ exclude: null
17
+ only:
18
+
data/test/test_helper.rb CHANGED
@@ -10,6 +10,7 @@ ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":me
10
10
  class ActiveSupport::TestCase
11
11
  include RailsERD
12
12
 
13
+ setup :reset_config_file
13
14
  teardown :reset_domain
14
15
 
15
16
  def create_table(table, columns = {}, pk = nil)
@@ -118,6 +119,16 @@ class ActiveSupport::TestCase
118
119
 
119
120
  private
120
121
 
122
+ def reset_config_file
123
+ RailsERD::Config.send :remove_const, :USER_WIDE_CONFIG_FILE
124
+ RailsERD::Config.send :const_set, :USER_WIDE_CONFIG_FILE,
125
+ File.expand_path("../../examples/erdconfig.not_exists", __FILE__)
126
+
127
+ RailsERD::Config.send :remove_const, :CURRENT_CONFIG_FILE
128
+ RailsERD::Config.send :const_set, :CURRENT_CONFIG_FILE,
129
+ File.expand_path("../../examples/erdconfig.not_exists", __FILE__)
130
+ end
131
+
121
132
  def reset_domain
122
133
  if defined? ActiveRecord
123
134
  ActiveRecord::Base.descendants.each do |model|
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../test_helper", File.dirname(__FILE__))
3
+
4
+ class ConfigTest < ActiveSupport::TestCase
5
+
6
+ test "load_config_gile should return blank hash when neither CURRENT_CONFIG_FILE nor USER_WIDE_CONFIG_FILE exist." do
7
+ expected_hash = {}
8
+ assert_equal expected_hash, RailsERD::Config.load
9
+ end
10
+
11
+ test "load_config_gile should return a hash from USER_WIDE_CONFIG_FILE when only USER_WIDE_CONFIG_FILE exists." do
12
+ set_user_config_file_to("erdconfig.example")
13
+
14
+ expected_hash = {
15
+ attributes: [:content, :foreign_key, :inheritance],
16
+ disconnected: true,
17
+ filename: "erd",
18
+ filetype: :pdf,
19
+ indirect: true,
20
+ inheritance: false,
21
+ markup: true,
22
+ notation: :simple,
23
+ orientation: :horizontal,
24
+ polymorphism: false,
25
+ warn: true,
26
+ title: "sample title",
27
+ exclude: nil,
28
+ only: nil
29
+ }
30
+ assert_equal expected_hash, RailsERD::Config.load
31
+ end
32
+
33
+ test "load_config_gile should return a hash from CURRENT_CONFIG_FILE when only CURRENT_CONFIG_FILE exists." do
34
+ set_local_config_file_to("erdconfig.another_example")
35
+
36
+ expected_hash = {
37
+ :attributes => [:primary_key]
38
+ }
39
+ assert_equal expected_hash, RailsERD::Config.load
40
+ end
41
+
42
+ test "load_config_gile should return a hash from CURRENT_CONFIG_FILE overriding USER_WIDE_CONFIG_FILE when both of them exist." do
43
+ set_user_config_file_to("erdconfig.example")
44
+ set_local_config_file_to("erdconfig.another_example")
45
+
46
+ expected_hash = {
47
+ attributes: [:primary_key],
48
+ disconnected: true,
49
+ filename: "erd",
50
+ filetype: :pdf,
51
+ indirect: true,
52
+ inheritance: false,
53
+ markup: true,
54
+ notation: :simple,
55
+ orientation: :horizontal,
56
+ polymorphism: false,
57
+ warn: true,
58
+ title: "sample title",
59
+ exclude: nil,
60
+ only: nil
61
+ }
62
+ assert_equal expected_hash, RailsERD::Config.load
63
+ end
64
+
65
+ test "normalize_value should return symbols in an array when key is :attributes and value is a comma-joined string." do
66
+ assert_equal [:content, :foreign_keys], normalize_value(:attributes, "content,foreign_keys")
67
+ end
68
+
69
+ test "normalize_value should return symbols in an array when key is :attributes and value is strings in an array." do
70
+ assert_equal [:content, :primary_keys], normalize_value(:attributes, ["content", "primary_keys"])
71
+ end
72
+
73
+ def normalize_value(key, value)
74
+ RailsERD::Config.new.send(:normalize_value, key, value)
75
+ end
76
+
77
+ def set_user_config_file_to(config_file)
78
+ RailsERD::Config.send :remove_const, :USER_WIDE_CONFIG_FILE
79
+ RailsERD::Config.send :const_set, :USER_WIDE_CONFIG_FILE,
80
+ File.expand_path("test/support_files/#{config_file}")
81
+ end
82
+
83
+ def set_local_config_file_to(config_file)
84
+ RailsERD::Config.send :remove_const, :CURRENT_CONFIG_FILE
85
+ RailsERD::Config.send :const_set, :CURRENT_CONFIG_FILE,
86
+ File.expand_path("test/support_files/#{config_file}")
87
+ end
88
+ end
metadata CHANGED
@@ -1,78 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-erd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rolf Timmermans
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
11
+ date: 2014-12-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '3.0'
19
+ version: '3.2'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '3.0'
26
+ version: '3.2'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: activesupport
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '3.0'
33
+ version: '3.2'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '3.0'
40
+ version: '3.2'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: ruby-graphviz
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: 1.0.4
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: 1.0.4
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: choice
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: 0.1.6
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: 0.1.6
78
69
  description: Automatically generate an entity-relationship diagram (ERD) for your
@@ -91,6 +82,7 @@ files:
91
82
  - lib/rails-erd.rb
92
83
  - lib/rails_erd.rb
93
84
  - lib/rails_erd/cli.rb
85
+ - lib/rails_erd/config.rb
94
86
  - lib/rails_erd/diagram.rb
95
87
  - lib/rails_erd/diagram/graphviz.rb
96
88
  - lib/rails_erd/diagram/templates/node.html.erb
@@ -104,9 +96,12 @@ files:
104
96
  - lib/rails_erd/railtie.rb
105
97
  - lib/rails_erd/tasks.rake
106
98
  - lib/rails_erd/version.rb
99
+ - test/support_files/erdconfig.another_example
100
+ - test/support_files/erdconfig.example
107
101
  - test/test_helper.rb
108
102
  - test/unit/attribute_test.rb
109
103
  - test/unit/cardinality_test.rb
104
+ - test/unit/config_test.rb
110
105
  - test/unit/diagram_test.rb
111
106
  - test/unit/domain_test.rb
112
107
  - test/unit/entity_test.rb
@@ -114,40 +109,36 @@ files:
114
109
  - test/unit/rake_task_test.rb
115
110
  - test/unit/relationship_test.rb
116
111
  - test/unit/specialization_test.rb
117
- homepage: http://rails-erd.rubyforge.org/
112
+ homepage: https://github.com/voormedia/rails-erd
118
113
  licenses: []
114
+ metadata: {}
119
115
  post_install_message:
120
116
  rdoc_options: []
121
117
  require_paths:
122
118
  - lib
123
119
  required_ruby_version: !ruby/object:Gem::Requirement
124
- none: false
125
120
  requirements:
126
- - - ! '>='
121
+ - - ">="
127
122
  - !ruby/object:Gem::Version
128
123
  version: '0'
129
- segments:
130
- - 0
131
- hash: 1960804951299581689
132
124
  required_rubygems_version: !ruby/object:Gem::Requirement
133
- none: false
134
125
  requirements:
135
- - - ! '>='
126
+ - - ">="
136
127
  - !ruby/object:Gem::Version
137
128
  version: '0'
138
- segments:
139
- - 0
140
- hash: 1960804951299581689
141
129
  requirements: []
142
130
  rubyforge_project: rails-erd
143
- rubygems_version: 1.8.23
131
+ rubygems_version: 2.4.5
144
132
  signing_key:
145
- specification_version: 3
133
+ specification_version: 4
146
134
  summary: Entity-relationship diagram for your Rails models.
147
135
  test_files:
136
+ - test/support_files/erdconfig.another_example
137
+ - test/support_files/erdconfig.example
148
138
  - test/test_helper.rb
149
139
  - test/unit/attribute_test.rb
150
140
  - test/unit/cardinality_test.rb
141
+ - test/unit/config_test.rb
151
142
  - test/unit/diagram_test.rb
152
143
  - test/unit/domain_test.rb
153
144
  - test/unit/entity_test.rb