sequel-schema-dot-generator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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/.rvmrc ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p385@sequel-dot-generator"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.18.8 (stable)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in sequel-schema-dot-generator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mailo Svetel
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,38 @@
1
+ # Sequel::Schema::Dot::Generator
2
+
3
+ Sequel database structure Dot language generator
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sequel-schema-dot-generator'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sequel-schema-dot-generator
18
+
19
+ ## Usage
20
+
21
+ require 'sequel/schema/dot/generator'
22
+
23
+ dot_db = Sequel::Schema::Dot::Generator::Generator
24
+ .new({ db: DB
25
+ }
26
+ )
27
+
28
+ puts dot_db.generate
29
+
30
+ =>
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,71 @@
1
+ require 'sequel/schema/dot/generator/version'
2
+ require 'erb'
3
+ require 'logger'
4
+ require 'sequel'
5
+
6
+ module Sequel
7
+ module Schema
8
+ module Dot
9
+ # Module for generating Sequel schema structure into Dot language format
10
+ module Generator
11
+ class Generator
12
+ @db = nil
13
+ @dot_template_path = nil
14
+ @logger = nil
15
+
16
+ # @todo Consider write the params as block
17
+ #
18
+ # @param [Hash] params Setup of Generator instance
19
+ # :db [Sequel::Database] required From this one will be generated the diagram
20
+ # :logger [Logger] optional Will be used for logging
21
+ # :dot_template_path [String] optional Template is supposed to be ERB template. Will be used as template for resulting Dot file
22
+ #
23
+ def initialize params
24
+ check_params params
25
+
26
+ @db = params[:db]
27
+ @logger = params[:logger] || Logger.new(STDERR)
28
+ @dot_template_path = params[:dot_template_path] || File.join(File.dirname(__FILE__), 'generator/diagram.dot.erb')
29
+ end
30
+
31
+ # @return [String] Content which can be passed to dot parsing tool
32
+ def generate
33
+ relations = []
34
+ tables = []
35
+
36
+ @db.tables.each do |table_name|
37
+ next if table_name == :schema_info
38
+ tables << [table_name, @db[table_name]]
39
+
40
+ # foreign keys by <table>_id name format
41
+ # @todo Read it from model
42
+ @db[table_name].columns.each do |column_name|
43
+ next unless column_name =~ /_id$/
44
+ foreign_column = column_name.to_s
45
+ foreign_table = foreign_column.gsub(/_id$/, '')
46
+ relations << [foreign_table, 'id', table_name, foreign_column]
47
+ end
48
+ end
49
+
50
+ ERB.new( File.read(@dot_template_path),nil,'>' ).result(binding)
51
+ end
52
+
53
+ private
54
+
55
+ # Checks if all parameters for new Object are alright
56
+ def check_params params
57
+ unless params[:db].is_a?Sequel::Database
58
+ raise 'Database connection is supposed to be Sequel::Database. %s given'%params[:database_connection].class.name
59
+ end
60
+ unless params[:dot_template_path].nil? || params[:dot_template_path].is_a?(String) || File.exist?(params[:dot_template_path])
61
+ raise 'Template path is supposed to be string with an existing file. %s given'%params[:dot_template_path].inspect
62
+ end
63
+ unless params[:logger].nil? || params[:logger].is_a?(Logger)
64
+ raise 'Logger is supposed to be... Logger, know. %s given'%params[:logger].inspect
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,18 @@
1
+ digraph G {
2
+ node [shape=none,fontname="DejaVu Sans"];
3
+ <% tables.each do |table_name, table| %>
4
+ <%= table_name %> [label=<
5
+ <table border="0" cellborder="1" cellspacing="0" cellpadding="4">
6
+ <tr><td bgcolor="lightgrey" PORT="users"><b><%= table_name %></b></td></tr>
7
+ <% table.columns.each do |column_name| %>
8
+ <tr><td PORT="<%= column_name %>"><%= column_name %></td></tr>
9
+ <% end %>
10
+ </table>
11
+ >]
12
+ <% end %>
13
+
14
+ <% relations.each do |from_tab, from_col, to_tab, to_col| %>
15
+ <%= '"%s":"%s" -> "%s":"%s"'%[from_tab, from_col, to_tab, to_col] %>
16
+
17
+ <% end %>
18
+ }
@@ -0,0 +1,9 @@
1
+ module Sequel
2
+ module Schema
3
+ module Dot
4
+ module Generator
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require File.expand_path 'lib/sequel/schema/dot/generator'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sequel-schema-dot-generator'
8
+ spec.version = Sequel::Schema::Dot::Generator::VERSION
9
+ spec.authors = ['Mailo Svetel']
10
+ spec.email = %w(development@rooland.cz)
11
+ spec.description = %q{This gem makes it easier to generate database schema overview image}
12
+ spec.summary = %q{Dot language format generator for Sequel schema structure}
13
+ spec.homepage = 'https://github.com/roolo/sequel-schema-dot-generator-gem'
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 = %w(lib)
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+
24
+ spec.add_dependency 'sequel'
25
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-schema-dot-generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mailo Svetel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sequel
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: This gem makes it easier to generate database schema overview image
63
+ email:
64
+ - development@rooland.cz
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rvmrc
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - lib/sequel/schema/dot/generator.rb
76
+ - lib/sequel/schema/dot/generator/diagram.dot.erb
77
+ - lib/sequel/schema/dot/generator/version.rb
78
+ - sequel-schema-dot-generator.gemspec
79
+ homepage: https://github.com/roolo/sequel-schema-dot-generator-gem
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
93
+ - 0
94
+ hash: 2048490745226108490
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ segments:
102
+ - 0
103
+ hash: 2048490745226108490
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.25
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Dot language format generator for Sequel schema structure
110
+ test_files: []