erde 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +25 -41
- data/bin/erde +8 -0
- data/erde.gemspec +1 -2
- data/lib/erde/cli.rb +83 -0
- data/lib/erde/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceaf6b839dab986b6926445fe3881ab0eb969549
|
4
|
+
data.tar.gz: 1b2b7ca815801782137c01d55ad4752fbb26a4da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 648f7365ef3d165e51f5ad20f835aa6f8d2003e3a600077b10f72c4de45b14dc18531884abeb65c6133e451214ba997866c2152d7faabf6ca40ccfdb13785097
|
7
|
+
data.tar.gz: b6a5b10fb2191b9ceea5be765fbbbf751e15de56a7af315a137102feeca4683b159aa00cd20f12c47cecf3360116d8388482cfbc8e9b55943fe70bdbd8717d92
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,41 +1,25 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
##
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
+
~~~
|
data/bin/erde
ADDED
data/erde.gemspec
CHANGED
@@ -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.
|
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"
|
data/lib/erde/cli.rb
ADDED
@@ -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
|
data/lib/erde/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Strauß
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
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:
|