schemapper 0.0.1

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: b83854970a41f8046d4e33f9048002f486f7f133
4
+ data.tar.gz: 54e803667cfb57900cb29b9fbf0a25e87515759b
5
+ SHA512:
6
+ metadata.gz: 07705276f474c13938028ee98f7f434e0a4565a9397617041424378f66ff9010b242dcc4c909926f64efb7a345e448b9410ca8df7aa243e6d91b3a6667c1f791
7
+ data.tar.gz: 3306c496c739da31da4a9772da262e7015dab2bc79bb57bcbce629adc95ac7cba0ebe191e5cf72ebc197ed166bac8b484f4313e80d6b9fff1c1efb3820dc61d2
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in schemapper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 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,29 @@
1
+ # Schemapper
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'schemapper'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install schemapper
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/schemapper ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yaml'
4
+ require 'json'
5
+
6
+ serialized_schema = `ruby #{File.dirname(__FILE__)}/../lib/schemapper.rb`
7
+ schema = YAML.load(serialized_schema)
8
+
9
+ html_path = File.expand_path('../../lib/schemapper/schemapper.html', __FILE__)
10
+ html_source = File.read(html_path) + '<script>window._schemapper = ' +
11
+ "#{schema.to_json};visualizeSchema()</script>"
12
+ temp_html = '/tmp/schemapper.html'
13
+
14
+ File.open(temp_html, 'w'){ |file| file.write(html_source) }
15
+
16
+ `open #{temp_html}`
data/lib/schemapper.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "#{Dir.pwd}/config/environment.rb"
2
+
3
+ Rails.application.eager_load!
4
+ models = ActiveRecord::Base.descendants
5
+ tables = models.map(&:table_name)
6
+
7
+ nodes = tables.map do |table|
8
+ { name: table }
9
+ end
10
+
11
+ all_links = models.each_with_index.flat_map do |model, index|
12
+ associations = model.reflections.map do |reflection|
13
+ target = reflection[1].table_name rescue nil
14
+ if target && tables.index(target)
15
+ { source: index, target: tables.index(target), value: rand(1..5) }
16
+ end
17
+ end
18
+ associations.compact
19
+ end
20
+ links = all_links.select(&:present?)
21
+
22
+ attrs = models.map do |model|
23
+ { table: model.table_name, attrs: model.attribute_names }
24
+ end
25
+
26
+ puts YAML.dump({ nodes: nodes, links: links, attributes: attrs.uniq })
@@ -0,0 +1,96 @@
1
+ <!DOCTYPE html>
2
+ <meta charset="utf-8">
3
+ <title>Schemapper</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.visualizeSchema = function() {
36
+ var width = window.innerWidth,
37
+ height = window.innerHeight,
38
+ graph = window._schemapper;
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
+ var table = d3.select(this).text();
75
+ var text = '<b>' + table + '</b><br>'
76
+ graph.attributes.forEach(function(attr) {
77
+ if (attr.table === table) {
78
+ text = text + '<br>' + attr.attrs.join('<br>');
79
+ }
80
+ })
81
+ d3.select('.footer').html(text);
82
+ })
83
+
84
+ force.on("tick", function() {
85
+ link.attr("x1", function(d) { return d.source.x; })
86
+ .attr("y1", function(d) { return d.source.y; })
87
+ .attr("x2", function(d) { return d.target.x; })
88
+ .attr("y2", function(d) { return d.target.y; });
89
+
90
+ node.attr("cx", function(d) { return d.x; })
91
+ .attr("cy", function(d) { return d.y; });
92
+ });
93
+ }
94
+
95
+ </script>
96
+ </body>
@@ -0,0 +1,3 @@
1
+ module Schemapper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'schemapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "schemapper"
8
+ spec.version = Schemapper::VERSION
9
+ spec.authors = ["Nathaniel Wroblewski"]
10
+ spec.email = ["nathanielwroblewski@gmail.com"]
11
+ spec.description = %q{Visualize your Rails schema}
12
+ spec.summary = %q{Database agnostic visualization of your Rails schema}
13
+ spec.homepage = "https://github.com/NathanielWroblewski/schemapper"
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: schemapper
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: 2014-01-04 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: :development
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Visualize your Rails schema
42
+ email:
43
+ - nathanielwroblewski@gmail.com
44
+ executables:
45
+ - schemapper
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/schemapper
55
+ - lib/schemapper.rb
56
+ - lib/schemapper/schemapper.html
57
+ - lib/schemapper/version.rb
58
+ - schemapper.gemspec
59
+ homepage: https://github.com/NathanielWroblewski/schemapper
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.0.5
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Database agnostic visualization of your Rails schema
83
+ test_files: []