cabbage 0.1.1 → 0.1.2
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.
- data/VERSION +1 -1
- data/cabbage.gemspec +2 -3
- data/lib/cabbage.rb +54 -33
- metadata +10 -11
- data/testbed.rb +0 -24
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/cabbage.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "cabbage"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Josh Lauer"]
|
@@ -27,8 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"cabbage.gemspec",
|
28
28
|
"lib/cabbage.rb",
|
29
29
|
"test/helper.rb",
|
30
|
-
"test/test_cabbage.rb"
|
31
|
-
"testbed.rb"
|
30
|
+
"test/test_cabbage.rb"
|
32
31
|
]
|
33
32
|
s.homepage = "http://github.com/josh-lauer/cabbage"
|
34
33
|
s.licenses = ["MIT"]
|
data/lib/cabbage.rb
CHANGED
@@ -17,15 +17,28 @@ module Cabbage
|
|
17
17
|
# a DOTfile.
|
18
18
|
def initialize(source = nil)
|
19
19
|
@raw_dotfile = "" # unparsed DOTfile
|
20
|
-
@
|
20
|
+
@graph_type = "" #
|
21
21
|
@title = ""
|
22
22
|
@header = {}
|
23
|
-
@
|
23
|
+
@nodes = []
|
24
24
|
@connections = []
|
25
25
|
source != nil if parse(source)
|
26
26
|
end
|
27
27
|
|
28
|
-
attr_accessor :raw_dotfile, :
|
28
|
+
attr_accessor :raw_dotfile, :graph_type, :title, :header, :nodes, :connections
|
29
|
+
|
30
|
+
# no public methods yet apart from accessors
|
31
|
+
|
32
|
+
# parsing methods below
|
33
|
+
private
|
34
|
+
|
35
|
+
def load_from_file(dotfile_path)
|
36
|
+
@raw_dotfile = IO.read(dotfile_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_from_string(dotfile)
|
40
|
+
@raw_dotfile = dotfile
|
41
|
+
end
|
29
42
|
|
30
43
|
def parse(source = nil)
|
31
44
|
begin
|
@@ -44,12 +57,26 @@ module Cabbage
|
|
44
57
|
end
|
45
58
|
end
|
46
59
|
|
47
|
-
|
48
|
-
|
49
|
-
|
60
|
+
# a dotfile has four components:
|
61
|
+
# graph_type, header, nodes, connections
|
62
|
+
def parse_dotfile
|
63
|
+
# the chunk is everything inside '{}'
|
64
|
+
raw_chunk = @raw_dotfile.split("{")[1].split("}")[0].strip
|
65
|
+
# pull out the header
|
66
|
+
raw_header = raw_chunk.match(/([\w\s*=".,\s\[\]_\\]+;)*/m)[0]
|
67
|
+
# find body by chopping header off chunk
|
68
|
+
raw_body = raw_chunk.sub(raw_header, "")
|
69
|
+
# split the body on '>];', which delimits the tables section
|
70
|
+
raw_connections = raw_body.split(">];")[-1].strip
|
71
|
+
# split out the tables section from the body
|
72
|
+
raw_tables = raw_body.split(">];")[0 .. -2].join(">];").strip + " \n>];"
|
50
73
|
|
51
|
-
|
52
|
-
@
|
74
|
+
# assemble the output hash
|
75
|
+
@graph_type = @raw_dotfile.match(/\A\s*((?:di)?graph)/)[1]
|
76
|
+
@title = @raw_dotfile.match(/\A\s*(?:di)?graph\s*(\w+)/)[1]
|
77
|
+
@header = parse_header(raw_header, ";")
|
78
|
+
@nodes = parse_nodes(raw_tables)
|
79
|
+
@connections = parse_connections(raw_connections)
|
53
80
|
end
|
54
81
|
|
55
82
|
def parse_header(raw_header, delimiter)
|
@@ -64,7 +91,7 @@ module Cabbage
|
|
64
91
|
return temp
|
65
92
|
end
|
66
93
|
|
67
|
-
def
|
94
|
+
def chop_tables(raw_tables)
|
68
95
|
{}.tap do |output|
|
69
96
|
raw_tables.scan(/\s*\"*([\w:]+)\"*\s*\[\w+\s*=\s*<(.+?)>\];/m).each do |n|
|
70
97
|
output[ n[0].gsub('\"', '').strip ] = n[1].strip
|
@@ -72,44 +99,38 @@ module Cabbage
|
|
72
99
|
end
|
73
100
|
end
|
74
101
|
|
102
|
+
def parse_nodes(raw_tables)
|
103
|
+
result = []
|
104
|
+
chop_tables(raw_tables).each do |name, table|
|
105
|
+
node = {:name => name.sub("m_", "")}
|
106
|
+
node[:fields] = []
|
107
|
+
if table.include?("|")
|
108
|
+
table.split("|")[1].scan(/port="([\w:]+)">[^<]+<[^>]+>(.+?)</m).each do |pair|
|
109
|
+
node[:fields] << { :name => pair[0], :type => pair[1] }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
result << node
|
113
|
+
end
|
114
|
+
result
|
115
|
+
end
|
116
|
+
|
75
117
|
def parse_connections(node_chunk)
|
76
118
|
output = []
|
77
119
|
node_chunk.split("\n").each do |this_line|
|
78
120
|
this_connection = {}
|
79
121
|
temp = this_line.split("->")
|
80
|
-
this_connection[
|
81
|
-
this_connection[
|
122
|
+
this_connection[:start_node] = temp[0].gsub('"', '').gsub('\\', '').strip
|
123
|
+
this_connection[:end_node] = temp[1].split("[")[0].gsub('"', '').gsub('\\', '').strip
|
82
124
|
tokens = temp[1].split("[")[1].split("]")[0].split(",")
|
83
125
|
tokens.each do |token_string|
|
84
126
|
token_pair = token_string.split("=")
|
85
|
-
this_connection[token_pair[0].strip.gsub('"', '').gsub('\\', '')] = token_pair[1].strip.gsub('"', '').gsub('\\', '')
|
127
|
+
this_connection[token_pair[0].strip.gsub('"', '').gsub('\\', '').to_sym] = token_pair[1].strip.gsub('"', '').gsub('\\', '')
|
86
128
|
end
|
87
129
|
output << this_connection
|
88
130
|
end
|
89
131
|
return output
|
90
132
|
end
|
91
133
|
|
92
|
-
# structure:
|
93
|
-
# title, header, tables, footer
|
94
|
-
def parse_dotfile
|
95
|
-
# the chunk is everything inside '{}'
|
96
|
-
raw_chunk = @raw_dotfile.split("{")[1].split("}")[0].strip
|
97
|
-
# pull out the header
|
98
|
-
raw_header = raw_chunk.match(/([\w\s*=".,\s\[\]_\\]+;)*/m)[0]
|
99
|
-
# find body by chopping header off chunk
|
100
|
-
raw_body = raw_chunk.sub(raw_header, "")
|
101
|
-
# split the body on '>];', which delimits the tables section
|
102
|
-
raw_connections = raw_body.split(">];")[-1].strip
|
103
|
-
# split out the tables section from the body
|
104
|
-
raw_tables = raw_body.split(">];")[0 .. -2].join(">];").strip + " \n>];"
|
105
|
-
|
106
|
-
# assemble the output hash
|
107
|
-
@type = @raw_dotfile.match(/\A\s*((?:di)?graph)/)[1]
|
108
|
-
@title = @raw_dotfile.match(/\A\s*(?:di)?graph\s*(\w+)/)[1]
|
109
|
-
@header = parse_header(raw_header, ";")
|
110
|
-
@tables = parse_tables(raw_tables)
|
111
|
-
@connections = parse_connections(raw_connections)
|
112
|
-
end
|
113
134
|
|
114
135
|
end
|
115
136
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cabbage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-24 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
16
|
-
requirement: &
|
16
|
+
requirement: &20776840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *20776840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &20774100 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *20774100
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &20772580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *20772580
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rcov
|
49
|
-
requirement: &
|
49
|
+
requirement: &20767660 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *20767660
|
58
58
|
description: More to come.
|
59
59
|
email: josh.lauer75@gmail.com
|
60
60
|
executables: []
|
@@ -74,7 +74,6 @@ files:
|
|
74
74
|
- lib/cabbage.rb
|
75
75
|
- test/helper.rb
|
76
76
|
- test/test_cabbage.rb
|
77
|
-
- testbed.rb
|
78
77
|
homepage: http://github.com/josh-lauer/cabbage
|
79
78
|
licenses:
|
80
79
|
- MIT
|
@@ -90,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
89
|
version: '0'
|
91
90
|
segments:
|
92
91
|
- 0
|
93
|
-
hash: -
|
92
|
+
hash: -4588039299790151145
|
94
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
94
|
none: false
|
96
95
|
requirements:
|
data/testbed.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
require 'irb'
|
4
|
-
require 'ruby-debug'
|
5
|
-
require 'cabbage'
|
6
|
-
|
7
|
-
class Object
|
8
|
-
# Return only the methods not present on basic objects
|
9
|
-
def interesting_methods
|
10
|
-
(self.methods - Object.instance_methods).sort
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def reload
|
15
|
-
@output = Cabbage.dotfile("ERD.dot")
|
16
|
-
end
|
17
|
-
|
18
|
-
@output = reload
|
19
|
-
# put stuff here you only want to run once
|
20
|
-
# ARGV.clear
|
21
|
-
IRB.setup nil
|
22
|
-
IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
|
23
|
-
require 'irb/ext/multi-irb'
|
24
|
-
IRB.irb nil, self
|