schemap 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/ScreenShot.png +0 -0
- data/bin/schemap +17 -0
- data/lib/schemap/schemap.html +97 -0
- data/lib/schemap/version.rb +3 -0
- data/lib/schemap.rb +26 -0
- data/schemap.gemspec +24 -0
- data/spec/schemap_spec.rb +34 -0
- data/spec/spec_helper.rb +4 -0
- data/test.rb +14 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6a903f81fd800a4911da04c164896bfc0b5e854f
|
4
|
+
data.tar.gz: dfc860b9e2e731c09b072254e9cace6429b71cfa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8685453301380b881e30ac5e4c3b74f43d06bb9a77190358e5f003d58c9fc5a53cf3ba3055decc5f83f48ae3989f081c90ff491ab48b216f086eb49fa4d6a42
|
7
|
+
data.tar.gz: 1196456cdc12578d5c052cd1172a47132d1f259fefe588f9a29097187f40e64fcacf8cc954e8f0d7e001d30b52e85e43cfb31e6babaa99a1463dc8f8d683b1d3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Nathaniel Wroblewski
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Schemap
|
2
|
+
|
3
|
+
Schemap helps you visualize your [Rails](https://github.com/rails/rails) schemas by mapping them to [D3](http://d3js.org/) force graphs.
|
4
|
+
|
5
|
+
## Screen Shot
|
6
|
+
![Schemap Screen Shot](https://raw.github.com/NathanielWroblewski/schemap/91dd6925b0e24b00cc7a6970662ef95dbda0e96e/ScreenShot.png)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'schemap'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install schemap
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
From the root of your Rails app, simply call:
|
25
|
+
|
26
|
+
$ schemap
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/ScreenShot.png
ADDED
Binary file
|
data/bin/schemap
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
serialized_schema = `ruby #{File.dirname(__FILE__)}/../lib/schemap.rb`
|
7
|
+
schema = YAML.load(serialized_schema)
|
8
|
+
|
9
|
+
html_path = File.expand_path('../../lib/schemap/schemap.html', __FILE__)
|
10
|
+
html_source = File.read(html_path) + "<script>window._schemap = #{schema.to_json};viz()</script>"
|
11
|
+
temp = "/tmp/schemap.html"
|
12
|
+
|
13
|
+
File.open(temp, 'w') do |file|
|
14
|
+
file.write(html_source)
|
15
|
+
end
|
16
|
+
|
17
|
+
`open #{temp}`
|
@@ -0,0 +1,97 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<meta charset="utf-8">
|
3
|
+
<title>Schemap</title>
|
4
|
+
<style>
|
5
|
+
|
6
|
+
.footer {
|
7
|
+
position: absolute;
|
8
|
+
right: 150px;
|
9
|
+
text-align: right;
|
10
|
+
font-size: 20px;
|
11
|
+
width: 200px;
|
12
|
+
height: 100%;
|
13
|
+
top: 100px;
|
14
|
+
}
|
15
|
+
|
16
|
+
.node {
|
17
|
+
cursor: pointer;
|
18
|
+
stroke: #3182bd;
|
19
|
+
stroke-width: 1.5px;
|
20
|
+
}
|
21
|
+
|
22
|
+
.link {
|
23
|
+
fill: none;
|
24
|
+
stroke: #9ecae1;
|
25
|
+
stroke-width: 1.5px;
|
26
|
+
}
|
27
|
+
|
28
|
+
</style>
|
29
|
+
<body>
|
30
|
+
<div class="footer">
|
31
|
+
</div>
|
32
|
+
<script src="http://d3js.org/d3.v3.min.js"></script>
|
33
|
+
<script>
|
34
|
+
|
35
|
+
window.viz = function() {
|
36
|
+
var width = window.innerWidth,
|
37
|
+
height = 500,
|
38
|
+
graph = window._schemap;
|
39
|
+
|
40
|
+
var color = d3.scale.category20();
|
41
|
+
|
42
|
+
var force = d3.layout.force()
|
43
|
+
.charge(-120)
|
44
|
+
.linkDistance(30)
|
45
|
+
.size([width, height]);
|
46
|
+
|
47
|
+
var svg = d3.select("body").append("svg")
|
48
|
+
.attr("width", width)
|
49
|
+
.attr("height", height);
|
50
|
+
|
51
|
+
force
|
52
|
+
.nodes(graph.nodes)
|
53
|
+
.links(graph.links)
|
54
|
+
.start();
|
55
|
+
|
56
|
+
var link = svg.selectAll(".link")
|
57
|
+
.data(graph.links)
|
58
|
+
.enter().append("line")
|
59
|
+
.attr("class", "link")
|
60
|
+
.style("stroke-width", function(d) { return Math.sqrt(d.value); });
|
61
|
+
|
62
|
+
var node = svg.selectAll(".node")
|
63
|
+
.data(graph.nodes)
|
64
|
+
.enter().append("circle")
|
65
|
+
.attr("class", "node")
|
66
|
+
.attr("r", 5)
|
67
|
+
.style("fill", function(d) { return color(d.group); })
|
68
|
+
.call(force.drag);
|
69
|
+
|
70
|
+
node.append("title")
|
71
|
+
.text(function(d) { return d.name; });
|
72
|
+
|
73
|
+
node.on('mouseover', function(d) {
|
74
|
+
debugger
|
75
|
+
var table = d3.select(this).text();
|
76
|
+
var text = '<b>' + table + '</b><br>'
|
77
|
+
graph.attributes.forEach(function(attr) {
|
78
|
+
if (attr.table === table) {
|
79
|
+
text = text + '<br>' + attr.attrs.join('<br>');
|
80
|
+
}
|
81
|
+
})
|
82
|
+
d3.select('.footer').html(text);
|
83
|
+
})
|
84
|
+
|
85
|
+
force.on("tick", function() {
|
86
|
+
link.attr("x1", function(d) { return d.source.x; })
|
87
|
+
.attr("y1", function(d) { return d.source.y; })
|
88
|
+
.attr("x2", function(d) { return d.target.x; })
|
89
|
+
.attr("y2", function(d) { return d.target.y; });
|
90
|
+
|
91
|
+
node.attr("cx", function(d) { return d.x; })
|
92
|
+
.attr("cy", function(d) { return d.y; });
|
93
|
+
});
|
94
|
+
}
|
95
|
+
|
96
|
+
</script>
|
97
|
+
</body>
|
data/lib/schemap.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "#{Dir.pwd}/config/environment.rb"
|
2
|
+
|
3
|
+
db_config = YAML.load_file("#{Dir.pwd}/config/database.yml")
|
4
|
+
ActiveRecord::Base.establish_connection db_config['development']
|
5
|
+
db_connection = ActiveRecord::Base.connection
|
6
|
+
table_names = db_connection.tables
|
7
|
+
table_names.shift # remove rails schema_migration table
|
8
|
+
|
9
|
+
tables = table_names.map do |table_name|
|
10
|
+
{ name: table_name }
|
11
|
+
end
|
12
|
+
|
13
|
+
associations = table_names.flat_map do |table|
|
14
|
+
table.classify.constantize.reflections.map do |reflection|
|
15
|
+
{ source: tables.index(name: table),
|
16
|
+
target: tables.index(name: reflection[1].table_name),
|
17
|
+
value: rand(1..5)
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attrs = table_names.map do |table|
|
23
|
+
{ table: table, attrs: db_connection.columns(table).map(&:name) }
|
24
|
+
end
|
25
|
+
|
26
|
+
puts YAML.dump({nodes: tables, links: associations, attributes: attrs})
|
data/schemap.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'schemap/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "schemap"
|
8
|
+
spec.version = Schemap::VERSION
|
9
|
+
spec.authors = ["Nathaniel Wroblewski"]
|
10
|
+
spec.email = ["nathanielwroblewski@gmail.com"]
|
11
|
+
spec.description = %q{Visualize your Rails schema}
|
12
|
+
spec.summary = %q{Converts your Rails schema to a D3 force graph}
|
13
|
+
spec.homepage = "https://github.com/NathanielWroblewski/schemap"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_dependency "pry"
|
23
|
+
spec.add_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/schemap'
|
3
|
+
|
4
|
+
describe Schemap, '#generate_schema'
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
# default to default schema location
|
13
|
+
# error if no schema
|
14
|
+
|
15
|
+
|
16
|
+
# describe Schemap::SchemaParser, '.replicate' do
|
17
|
+
# it 'maps tables to associations and attributes' do
|
18
|
+
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
|
22
|
+
|
23
|
+
# db = ActiveRecord::Base.connection
|
24
|
+
# db.tables.map do |table|
|
25
|
+
# {table =>
|
26
|
+
# {attributes:
|
27
|
+
# (db.columns(table).map(&:name)),
|
28
|
+
# associations:
|
29
|
+
# table.classify.constantize.reflections.map { |r|
|
30
|
+
# r[1].table_name
|
31
|
+
# }
|
32
|
+
# }
|
33
|
+
# }
|
34
|
+
# end
|
data/spec/spec_helper.rb
ADDED
data/test.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rails'
|
3
|
+
require 'active_record'
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
binding.pry
|
7
|
+
|
8
|
+
db_config = YAML.load_file("#{Dir.pwd}/config/database.yml")
|
9
|
+
ActiveRecord::Base.establish_connection db_config['development']
|
10
|
+
db = ActiveRecord::Base.connection
|
11
|
+
p db.tables
|
12
|
+
|
13
|
+
schema = Schemap::Schemap.generate_schema db.tables
|
14
|
+
p schema
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: schemap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathaniel Wroblewski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Visualize your Rails schema
|
56
|
+
email:
|
57
|
+
- nathanielwroblewski@gmail.com
|
58
|
+
executables:
|
59
|
+
- schemap
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- ScreenShot.png
|
69
|
+
- bin/schemap
|
70
|
+
- lib/schemap.rb
|
71
|
+
- lib/schemap/schemap.html
|
72
|
+
- lib/schemap/version.rb
|
73
|
+
- schemap.gemspec
|
74
|
+
- spec/schemap_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
- test.rb
|
77
|
+
homepage: https://github.com/NathanielWroblewski/schemap
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.5
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Converts your Rails schema to a D3 force graph
|
101
|
+
test_files:
|
102
|
+
- spec/schemap_spec.rb
|
103
|
+
- spec/spec_helper.rb
|