rails-erd-d3 0.0.19 → 0.2.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
  SHA1:
3
- metadata.gz: ad72e9ff1d52dcf6df66fbd7048f0bfe1aea4cfc
4
- data.tar.gz: 7aff46e82e02896d25b07d71f31f91fad586f3cd
3
+ metadata.gz: 71624687eef61c09307d3e7496ccb9dd796e745d
4
+ data.tar.gz: 3749918b6bcc5f93fbb8921e0a5f8bdb86c46cee
5
5
  SHA512:
6
- metadata.gz: bdb5e01b5e24ec23d22b57bef68ad5074472f37bc297d9b5c325397070f6b149e996213e0133c5cc14c568d82cdef7e1fc969dbd81c1552238f100a58f70105c
7
- data.tar.gz: b2e8891f5788fa788a1842b9375f2cc763d0e3104368248e98b08846586ed693f772b6dfb52371e69ff8f34a6c14484c3aa3556f741ec66a596c0d885a4e7bda
6
+ metadata.gz: a13af895afc5abea2a951ca5b6c30b6ff6d66456b3a1dfe5cb74a640903aef4733b58d3e5e151fda0c043d5c54345116e35d79d43b2e394ca4a01a9e7aa7284d
7
+ data.tar.gz: d87595c0366a62d87f481b483b387110eec889a3fcaa28b33cd04a4ef95dccbc0931344f54d8e154a44877d695bf7b685f3732f67a288ea29b937187d27f2458
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rails-erd-d3.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "activerecord"
8
+ gem "sqlite3"
9
+ end
data/README.md CHANGED
@@ -1,11 +1,15 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/rails-erd-d3.svg)](https://badge.fury.io/rb/rails-erd-d3)
2
2
  [![Code Climate](https://codeclimate.com/github/RomanKrasavtsev/rails-erd-d3/badges/gpa.svg)](https://codeclimate.com/github/RomanKrasavtsev/rails-erd-d3)
3
3
  [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/RomanKrasavtsev/rails-erd-d3/master/LICENSE.txt)
4
+ [![Build Status](https://travis-ci.org/RomanKrasavtsev/rails-erd-d3.svg?branch=master)](https://travis-ci.org/RomanKrasavtsev/rails-erd-d3)
4
5
 
5
6
  # Rails-ERD-D3
6
7
 
7
8
  Create entity–relationship diagram with D3.js for your Rails application.
8
9
 
10
+ ![Rails-ERD-D3](https://github.com/RomanKrasavtsev/rails-erd-d3/raw/master/rails-erd-d3.gif)
11
+
12
+
9
13
  ## Installation
10
14
 
11
15
  Add this line to your application's Gemfile:
@@ -23,12 +27,8 @@ And then execute for creating file erd.html:
23
27
 
24
28
  ## Todo
25
29
 
26
- - Optimize get_modals
27
- - Change button and header colour
28
- - Add to Gemfile for test environment
29
- - activerecord
30
- - sqlite3 (ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:")
31
30
  - Add tests
31
+ - ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
32
32
  - Sort nodes by label
33
33
  - Check associations
34
34
  - [X] belongs_to
data/lib/rails_erd_d3.rb CHANGED
@@ -2,6 +2,16 @@ require "json"
2
2
  require "erb"
3
3
 
4
4
  class RailsErdD3
5
+ ASSOCIATIONS = %w(
6
+ belongs_to
7
+ has_one
8
+ has_many
9
+ has_many_through
10
+ has_one_through
11
+ has_and_belongs_to_many
12
+ polymorphic
13
+ )
14
+
5
15
  def self.get_rails_version
6
16
  Rails::VERSION::MAJOR
7
17
  end
@@ -14,6 +24,8 @@ class RailsErdD3
14
24
  klass = ApplicationRecord
15
25
  end
16
26
 
27
+ Rails.application.eager_load!
28
+ klass.connection
17
29
  @@models = ObjectSpace.each_object(Class).select { |o| o.superclass == klass } || []
18
30
  end
19
31
 
@@ -32,11 +44,13 @@ class RailsErdD3
32
44
 
33
45
  model.reflections.each do |refl_name, refl_data|
34
46
  next if refl_data.options[:polymorphic]
35
- refl_model = (refl_data.options[:class_name] || refl_name).underscore
36
-
47
+ refl_model = (refl_data.options[:class_name] || refl_name).underscore
48
+ association = refl_data.macro.to_s + (refl_data.options[:through] ? '_through' : '')
49
+ color_index = ASSOCIATIONS.index(association)
37
50
  links << {
38
51
  source: models_list[model.model_name.plural.capitalize],
39
- target: models_list[refl_model.pluralize.capitalize]
52
+ target: models_list[refl_model.pluralize.capitalize],
53
+ color: color_index
40
54
  }
41
55
  end
42
56
  end
@@ -46,8 +60,6 @@ class RailsErdD3
46
60
  end
47
61
 
48
62
  def self.create
49
- Rails.application.eager_load!
50
-
51
63
  file = File.new("erd.html", "w")
52
64
  file.puts(
53
65
  "<!DOCTYPE HTML>"\
@@ -29,7 +29,7 @@
29
29
  .data(data.links)
30
30
  .enter()
31
31
  .append('line')
32
- .attr('stroke', 'black');
32
+ .attr('stroke', function(d){return colorScale(d.color)});
33
33
 
34
34
  var node = svg.selectAll('.node')
35
35
  .data(data.nodes)
@@ -33,9 +33,33 @@
33
33
  </tbody>
34
34
  </table>
35
35
  </div>
36
+
37
+ <div class="panel panel-primary">
38
+ <div class="panel-heading">Table Structure</div>
39
+ <table class="table table-hover">
40
+ <thead>
41
+ <tr>
42
+ <th>#</th>
43
+ <th>name</th>
44
+ <th>macro</th>
45
+ <th>foreign_key</th>
46
+ </tr>
47
+ </thead>
48
+ <tbody>
49
+ <% models.columns_hash.each_with_index do |k, v, index| %>
50
+ <tr>
51
+ <th><%= index + 1 %></th>
52
+ <td><%= k %></td>
53
+ <td><%= v.type %></td>
54
+ </tr>
55
+ <% end %>
56
+ </tbody>
57
+ </table>
58
+ </div>
36
59
  </div>
60
+
37
61
  <div class="modal-footer">
38
- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
62
+ <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
39
63
  </div>
40
64
  </div>
41
65
  </div>
data/rails-erd-d3.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "rails-erd-d3"
7
7
  spec.authors = ["Roman Krasavtsev"]
8
8
  spec.email = ["mr.krasavtsev@gmail.com"]
9
- spec.version = "0.0.19"
9
+ spec.version = "0.2.0"
10
10
  spec.summary = "Entity–relationship diagram with D3.js for Rails application"
11
11
  spec.description = "This gem creates entity–relationship diagram with D3.js for your Rails application"
12
12
  spec.homepage = "https://github.com/RomanKrasavtsev/rails-erd-d3"
data/rails-erd-d3.gif ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-erd-d3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Krasavtsev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-06 00:00:00.000000000 Z
11
+ date: 2016-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,6 +76,7 @@ files:
76
76
  - lib/templates/modals.html.erb
77
77
  - lib/templates/nav.html
78
78
  - rails-erd-d3.gemspec
79
+ - rails-erd-d3.gif
79
80
  homepage: https://github.com/RomanKrasavtsev/rails-erd-d3
80
81
  licenses:
81
82
  - MIT