erde 0.1.0 → 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: d0f08552b8e901a15a813a002681a23439db87dd
4
- data.tar.gz: f762128988f70ce8201f52067bd009b866183947
3
+ metadata.gz: ceaf6b839dab986b6926445fe3881ab0eb969549
4
+ data.tar.gz: 1b2b7ca815801782137c01d55ad4752fbb26a4da
5
5
  SHA512:
6
- metadata.gz: 76c8a68e084673f3cd1b9212512da452026ec8a50ee3ead782bea423904706b6a0d2995fc25c5e4ef8ffd30d49256d499d0fe700a8db59deb5e92cd6dfbaa297
7
- data.tar.gz: 632e7c19fcd74b2d03373e958be99b4cd7f37a0f8314413dbe493ebc720c41dc0b929828dee8895eed9ebf7f580ee7b38e0cf1c7ab944706010230bfa51b0043
6
+ metadata.gz: 648f7365ef3d165e51f5ad20f835aa6f8d2003e3a600077b10f72c4de45b14dc18531884abeb65c6133e451214ba997866c2152d7faabf6ca40ccfdb13785097
7
+ data.tar.gz: b6a5b10fb2191b9ceea5be765fbbbf751e15de56a7af315a137102feeca4683b159aa00cd20f12c47cecf3360116d8388482cfbc8e9b55943fe70bdbd8717d92
@@ -0,0 +1,3 @@
1
+ ## 0.2.0
2
+ - Support text schemas.
3
+ - Output the diagram as PNG.
data/README.md CHANGED
@@ -1,41 +1,25 @@
1
- # Erde
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/erde`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'erde'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install erde
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/erde.
36
-
37
-
38
- ## License
39
-
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
1
+ # Entity-Relationship-Diagramm-Erzeuger
2
+ A simple tool to generate Entity-Relationship-Diagrams based on text input or directly from a PostgreSQL database. The format of the text schema is inspired and based on ["erd" by Andrew Gallant](https://github.com/BurntSushi/erd).
3
+
4
+ ## Install
5
+ Make sure you have [Graphviz](http://graphviz.org/) installed and available in your `$PATH`. Install the gem with `gem install erde` or add it to your `Gemfile`.
6
+
7
+ ## CLI Usage
8
+ ~~~txt
9
+ bin/erde file docs/schema.txt docs/schema.png
10
+ ~~~
11
+
12
+ ## Text Schema Format
13
+ ~~~txt
14
+ [identities]
15
+ id
16
+ password
17
+ email
18
+
19
+ [players]
20
+ id
21
+ name
22
+ identity_id
23
+
24
+ players:identity_id -- identities:id
25
+ ~~~
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pathname"
4
+ bin_file = Pathname.new(__FILE__).realpath
5
+ $:.unshift File.expand_path("../../lib", bin_file)
6
+
7
+ require "erde/cli"
8
+ Erde::CLI.start(*ARGV)
@@ -15,8 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.executables = "erde"
20
19
  spec.require_paths = ["lib"]
21
20
 
22
21
  spec.add_development_dependency "bundler", "~> 1.12"
@@ -0,0 +1,83 @@
1
+ require "erde"
2
+ require "pathname"
3
+ require "open3"
4
+
5
+ class Erde::CLI
6
+ def self.start(*args)
7
+ command = args.shift.strip
8
+
9
+ if command == "file"
10
+ file = Pathname(args.shift.strip)
11
+ input = file.read
12
+ text_transformer = Erde::TextTransformer.new(input)
13
+ hash_schema = text_transformer.to_hash
14
+ end
15
+
16
+ hash_transformer = Erde::HashTransformer.new(hash_schema)
17
+ dot_schema = hash_transformer.to_dot
18
+
19
+ output_file = args.shift.strip
20
+
21
+ layouted_graph, dot_log = Open3.capture3("dot -Tpng -o #{output_file}", stdin_data: dot_schema)
22
+ end
23
+ end
24
+
25
+ class Erde::HashTransformer
26
+ def initialize(hash)
27
+ @hash = hash
28
+ end
29
+
30
+ def to_dot
31
+ schema_string = ""
32
+ schema_string << "digraph tables {"
33
+ schema_string << "node [shape=Mrecord rankdir=LR];"
34
+
35
+ @hash.each_pair do |table_name, table_schema|
36
+ schema_string << "#{table_name} [label=\"{#{table_name}|#{table_schema['columns'].map {|c| "<#{c}>#{c}" }.join("|")}}\"];"
37
+
38
+ table_schema['relations'].each_pair do |column, target|
39
+ schema_string << "#{table_name}:#{column} -> #{target['table']}:#{target['column']};"
40
+ end
41
+ end
42
+
43
+ schema_string << "}"
44
+
45
+ schema_string
46
+ end
47
+ end
48
+
49
+ class Erde::TextTransformer
50
+ def initialize(text)
51
+ @lines = text.lines
52
+ end
53
+
54
+ def to_hash
55
+ generated_hash = {}
56
+ current_table = nil
57
+
58
+ @lines.each do |line|
59
+ cleaned_line = line.strip
60
+
61
+ if current_table && cleaned_line.length > 0
62
+ generated_hash[current_table]['columns'] << cleaned_line
63
+ end
64
+
65
+ if cleaned_line.length == 0
66
+ current_table = nil
67
+ end
68
+
69
+ if match = cleaned_line.match(/^\[(\w+)\]/)
70
+ current_table = match[1]
71
+ generated_hash[current_table] = {}
72
+ generated_hash[current_table]['columns'] = []
73
+ generated_hash[current_table]['relations'] = {}
74
+ end
75
+
76
+ if match = cleaned_line.match(/^(\w+):(\w+) -- (\w+):(\w+)/)
77
+ generated_hash[match[1]]['relations'][match[2]] = { 'table' => match[3], 'column' => match[4] }
78
+ end
79
+ end
80
+
81
+ generated_hash
82
+ end
83
+ end
@@ -1,3 +1,3 @@
1
1
  module Erde
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erde
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Strauß
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-13 00:00:00.000000000 Z
11
+ date: 2016-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,20 +56,24 @@ description: Generate good looking Entity-Relationship-Diagrams from text files
56
56
  a PostgreSQL database.
57
57
  email:
58
58
  - david@strauss.io
59
- executables: []
59
+ executables:
60
+ - erde
60
61
  extensions: []
61
62
  extra_rdoc_files: []
62
63
  files:
63
64
  - ".gitignore"
64
65
  - ".travis.yml"
66
+ - CHANGELOG.md
65
67
  - Gemfile
66
68
  - LICENSE.txt
67
69
  - README.md
68
70
  - Rakefile
69
71
  - bin/console
72
+ - bin/erde
70
73
  - bin/setup
71
74
  - erde.gemspec
72
75
  - lib/erde.rb
76
+ - lib/erde/cli.rb
73
77
  - lib/erde/version.rb
74
78
  homepage: https://github.com/edgycircle/erde
75
79
  licenses: