dogviz 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c23418b41abd8b0f615a020215d9968d0fc4721
4
- data.tar.gz: 6d551216ea306d8a32a2ea800185cea191d3a4b9
3
+ metadata.gz: f52b08f82c2ec0119948a8fbf396929b2a6acffc
4
+ data.tar.gz: 775a8100eff08d29605903ec9023aa0033d9bec2
5
5
  SHA512:
6
- metadata.gz: 59c857b69bf82a837eb7415e3e4ed3e7fffba9a368e46665efef66a603015d79eb7ae23764b5cc706fb90997d161263270a1b9062d86a239354078df5171acb2
7
- data.tar.gz: a623e7f949b62d1998167796e14d6fb386625a10839dc0ac2aad62faf410c4fcc6a944d75c53134e9e5db8b3c23afc83935ca23e96f4bbb2726b31958630e2a5
6
+ metadata.gz: e23bb1161e281cafc883f1a0b2021b1c17863b290c6c946a55ccc55cdd2c341a0e3be6161999e37695f5444b816a741eaf89ce7ef2e57969aaf2836d0d44f84f
7
+ data.tar.gz: ac257f552ae52796cad6d490fbea55c27ba71b15bc182b717626387485f959467179f170a351f2c1e2eb510631f8f1a701dd421ca87822e0f9c17b05352c3038
data/dogviz.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
22
  spec.add_development_dependency 'simplecov', '~> 0'
23
23
  spec.add_development_dependency 'colorize', '~> 0'
24
+ spec.add_development_dependency 'nokogiri', '~> 1.6'
24
25
 
25
26
  spec.add_dependency 'ruby-graphviz', '~> 1'
26
27
  end
@@ -1,3 +1,3 @@
1
1
  module Dogviz
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/dogviz.rb CHANGED
@@ -8,9 +8,6 @@ module Dogviz
8
8
  parts += name.split /\s/
9
9
  parts.join '_'
10
10
  end
11
- def graph
12
- parent.graph
13
- end
14
11
  def root
15
12
  ancestors.last
16
13
  end
@@ -36,6 +33,15 @@ module Dogviz
36
33
  @rollup = true
37
34
  self
38
35
  end
36
+ def skip!
37
+ @skip = true
38
+ self
39
+ end
40
+
41
+ def skip?
42
+ @skip
43
+ end
44
+
39
45
  def under_rollup?
40
46
  ancestors.any? &:rollup?
41
47
  end
@@ -88,6 +94,7 @@ module Dogviz
88
94
  @id = create_id(name, parent)
89
95
  @pointers = []
90
96
  @rollup = false
97
+ @skip = false
91
98
  @edge_heads = []
92
99
 
93
100
  rollup! if options[:rollup]
@@ -105,10 +112,6 @@ module Dogviz
105
112
  renderer.render_node(parent, id, render_options, attributes)
106
113
  end
107
114
 
108
- def node
109
- graph.find_node(id)
110
- end
111
-
112
115
  def points_to_all(*others)
113
116
  others.each {|other|
114
117
  points_to other
@@ -117,16 +120,11 @@ module Dogviz
117
120
 
118
121
  def points_to(other, options = {})
119
122
  setup_render_edge(other, options)
120
- end
121
-
122
- def pointees
123
- pointers.map {|e|
124
- e[:other]
125
- }
123
+ other
126
124
  end
127
125
 
128
126
  def render(renderer)
129
- do_render_node(renderer) unless in_rollup?
127
+ do_render_node(renderer) unless in_rollup? || skip?
130
128
  end
131
129
 
132
130
  def render_edges(renderer)
@@ -159,14 +157,40 @@ module Dogviz
159
157
  from = from.parent
160
158
  end
161
159
 
162
- return if from == self && from.in_rollup?
160
+ return if from.skip?
163
161
 
162
+ return if from == self && from.in_rollup?
164
163
  return if from == other
165
- return if edge_heads.include? other
164
+ return if already_added_connection?(other)
166
165
 
167
- edge_heads << other
168
- render_options = pointer[:options]
169
- renderer.render_edge(from, other, render_options)
166
+ if other.skip?
167
+ others = resolve_skipped_others other
168
+ else
169
+ others = [other]
170
+ end
171
+
172
+ others.each do |other|
173
+ edge_heads << other
174
+ render_options = pointer[:options]
175
+ renderer.render_edge(from, other, render_options)
176
+ end
177
+ end
178
+
179
+ def already_added_connection?(other)
180
+ edge_heads.include? other
181
+ end
182
+
183
+ def resolve_skipped_others(skipped)
184
+ resolved = []
185
+ skipped.pointers.each {|pointer|
186
+ next_in_line = pointer[:other]
187
+ if next_in_line.skip?
188
+ resolved += resolve_skipped_others next_in_line
189
+ else
190
+ resolved << next_in_line
191
+ end
192
+ }
193
+ resolved
170
194
  end
171
195
  end
172
196
 
@@ -182,6 +206,7 @@ module Dogviz
182
206
  @parent = parent
183
207
  @name = name
184
208
  @id = create_id(name, parent)
209
+ @skip = false
185
210
 
186
211
  init_rollup options
187
212
 
@@ -215,14 +240,6 @@ module Dogviz
215
240
  }
216
241
  end
217
242
 
218
- def node
219
- if render_type == :node
220
- graph.find_node(render_id)
221
- elsif render_type == :subgraph
222
- @subgraph
223
- end
224
- end
225
-
226
243
  private
227
244
 
228
245
  def do_render_subgraph(renderer)
@@ -337,10 +354,6 @@ module Dogviz
337
354
  @rendered = false
338
355
  end
339
356
 
340
- def node
341
- graph
342
- end
343
-
344
357
  def output(*args)
345
358
  render
346
359
  out = graph.output *args
@@ -0,0 +1,3 @@
1
+ require "test/unit"
2
+ require_relative '../lib/dogviz'
3
+ SimpleCov.root('..') if Object.const_defined?('SimpleCov')
@@ -0,0 +1,72 @@
1
+ require 'nokogiri'
2
+
3
+ module Tests
4
+ class NamesAccessor
5
+ def initialize(graph)
6
+ @graph = graph
7
+ end
8
+ def containers
9
+ names @graph.container_nodes
10
+ end
11
+ def things
12
+ names @graph.thing_nodes
13
+ end
14
+ def edges
15
+ names @graph.edge_nodes
16
+ end
17
+
18
+ private
19
+ attr_reader :graph
20
+
21
+ def names(nodes)
22
+ nodes.map { |g|
23
+ g.css('text').text
24
+ }
25
+ end
26
+ end
27
+
28
+ class SvgGraph
29
+ def self.parse_file(svg_filename)
30
+ SvgGraph.new File.read(svg_filename)
31
+ end
32
+
33
+ def initialize(svg)
34
+ @doc = Nokogiri::XML(svg) {|config| config.noblanks }
35
+ end
36
+
37
+ def title
38
+ title_prefix = '<!-- Title: '
39
+ title_end = ' Pages: '
40
+ title_node_text = comments.find { |c|
41
+ c.to_s.start_with? title_prefix
42
+ }.to_s
43
+ title_node_text.gsub(title_prefix, '').split(title_end).first
44
+ end
45
+
46
+ def container_nodes
47
+ @doc.css 'g.cluster'
48
+ end
49
+
50
+ def thing_nodes
51
+ @doc.css 'g.node'
52
+ end
53
+
54
+ def edge_nodes
55
+ @doc.css 'g.edge'
56
+ end
57
+
58
+ def names_of
59
+ NamesAccessor.new self
60
+ end
61
+
62
+ def to_s
63
+ @doc.to_xml indent: 2
64
+ end
65
+
66
+ private
67
+
68
+ def comments
69
+ @doc.children.select &:comment?
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,45 @@
1
+ require_relative 'setup_tests'
2
+ require_relative 'svg_graph'
3
+
4
+ module Tests
5
+ class TestDogvizFunctionally < Test::Unit::TestCase
6
+
7
+ def svg_outfile
8
+ '/tmp/dogviz_functional_test.svg'
9
+ end
10
+
11
+ def setup
12
+ File.delete svg_outfile if File.exist?(svg_outfile)
13
+ end
14
+
15
+ include Dogviz
16
+ def test_outputs_svg_graph
17
+
18
+ sys = System.new 'family'
19
+
20
+ house = sys.container 'household'
21
+
22
+ cat = house.thing 'cat'
23
+ dog = house.thing 'dog'
24
+
25
+ mum = house.thing 'mum'
26
+ son = house.thing 'son'
27
+
28
+ mum.points_to son, name: 'parents'
29
+ son.points_to mum, name: 'respects'
30
+
31
+ cat.points_to dog, name: 'chases'
32
+ dog.points_to son, name: 'follows'
33
+
34
+ sys.output svg: svg_outfile
35
+
36
+ graph = SvgGraph.parse_file svg_outfile
37
+
38
+ assert_include graph.title, 'family'
39
+ assert_equal ['household'], graph.names_of.containers
40
+ assert_equal ['cat', 'dog', 'son', 'mum'], graph.names_of.things
41
+ assert_equal ['chases', 'follows', 'parents', 'respects'], graph.names_of.edges
42
+ end
43
+
44
+ end
45
+ end
@@ -1,6 +1,4 @@
1
- require "test/unit"
2
-
3
- require_relative '../lib/dogviz'
1
+ require_relative 'setup_tests'
4
2
 
5
3
  class TestDogvizGraph < Test::Unit::TestCase
6
4
  include Dogviz
@@ -80,4 +78,12 @@ class TestDogvizGraph < Test::Unit::TestCase
80
78
  })
81
79
  end
82
80
 
81
+ def test_root
82
+ group = sys.group('g')
83
+ nested_group = group.group('nested group')
84
+ thing1 = group.thing('n1')
85
+
86
+ assert_equal sys, thing1.root
87
+ end
88
+
83
89
  end
@@ -1,6 +1,4 @@
1
- require "test/unit"
2
-
3
- require_relative '../lib/dogviz'
1
+ require_relative 'setup_tests'
4
2
 
5
3
  class TestDogvizGraphvizRendering < Test::Unit::TestCase
6
4
  include Dogviz
@@ -171,6 +169,110 @@ class TestDogvizGraphvizRendering < Test::Unit::TestCase
171
169
  assert_equal('entry->group group->exit', connections)
172
170
  end
173
171
 
172
+ def test_skip_one_thing_with_one_onward_connection
173
+ a = sys.thing('a')
174
+ b = sys.thing('b')
175
+ c = sys.thing('c')
176
+
177
+ a.points_to b
178
+ b.points_to c
179
+
180
+ b.skip!
181
+
182
+ assert_equal('a->c', connections)
183
+ end
184
+
185
+ def test_skip_one_thing_with_multiple_onward_connections
186
+ a = sys.thing('a')
187
+ b = sys.thing('b')
188
+ out1 = sys.thing('out1')
189
+ out2 = sys.thing('out2')
190
+
191
+ a.points_to b
192
+ b.points_to_all out1, out2
193
+
194
+ b.skip!
195
+
196
+ assert_equal('a->out1 a->out2', connections)
197
+ end
198
+
199
+ def test_skip_one_thing_with_multiple_inward_connections
200
+ in1 = sys.thing('in1')
201
+ in2 = sys.thing('in2')
202
+ skipper = sys.thing('skipper')
203
+ out = sys.thing('out')
204
+
205
+ in1.points_to skipper
206
+ in2.points_to skipper
207
+ skipper.points_to out
208
+
209
+ skipper.skip!
210
+
211
+ assert_equal('in1->out in2->out', connections)
212
+ end
213
+
214
+ def test_skip_one_thing_with_multiple_inward_and_outward_connections
215
+ in1 = sys.thing('in1')
216
+ in2 = sys.thing('in2')
217
+ skipper = sys.thing('skipper')
218
+ out1 = sys.thing('out1')
219
+ out2 = sys.thing('out2')
220
+
221
+ in1.points_to skipper
222
+ in2.points_to skipper
223
+ skipper.points_to out1
224
+ skipper.points_to out2
225
+
226
+ skipper.skip!
227
+
228
+ assert_equal('in1->out1 in1->out2 in2->out1 in2->out2', connections)
229
+ end
230
+
231
+ def test_skip_multiple_things_with_one_onward_connection
232
+ start = sys.thing('start')
233
+ skip1 = sys.thing('skip1')
234
+ skip2 = sys.thing('skip2')
235
+ skip3 = sys.thing('skip3')
236
+ finish = sys.thing('finish')
237
+
238
+ start.points_to(skip1).points_to(skip2).points_to(skip3).points_to finish
239
+
240
+ skip1.skip!
241
+ skip2.skip!
242
+ skip3.skip!
243
+
244
+ assert_equal('start->finish', connections)
245
+ end
246
+
247
+ def test_skip_multiple_things_with_multiple_onward_connections
248
+ start = sys.thing('start')
249
+ skip1 = sys.thing('skip1')
250
+ skip2 = sys.thing('skip2')
251
+ skip3 = sys.thing('skip3')
252
+ skipX = sys.thing('skip_x')
253
+ skipY = sys.thing('skip_y')
254
+ finish1 = sys.thing('finish1')
255
+ finish2 = sys.thing('finish2')
256
+
257
+ start.points_to(skip1).points_to(skip2)
258
+ skip2.points_to(skip3).points_to(skipX).points_to finish1
259
+ skip2.points_to(skipY).points_to finish2
260
+
261
+ skip1.skip!
262
+ skip2.skip!
263
+ skip3.skip!
264
+ skipX.skip!
265
+ skipY.skip!
266
+
267
+ assert_equal('start->finish1 start->finish2', connections)
268
+ end
269
+
270
+ def test_skipped_thing_will_not_be_rendered
271
+ sys.thing('a').skip!
272
+
273
+ assert_nil find('a')
274
+ end
275
+
174
276
  def test_find_thing
175
277
  sys.group('top').thing('needle')
176
278
 
@@ -227,10 +329,6 @@ class TestDogvizGraphvizRendering < Test::Unit::TestCase
227
329
  }.join sep
228
330
  end
229
331
 
230
- def connected_ids
231
- (edges.map(&:tail_node) + edges.map(&:head_node)).uniq
232
- end
233
-
234
332
  def edges
235
333
  graph.each_edge
236
334
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - damned
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-29 00:00:00.000000000 Z
11
+ date: 2016-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: ruby-graphviz
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -90,7 +104,6 @@ files:
90
104
  - ".gitignore"
91
105
  - ".ruby-version"
92
106
  - Gemfile
93
- - Gemfile.lock
94
107
  - LICENSE.txt
95
108
  - README.md
96
109
  - Rakefile
@@ -99,8 +112,11 @@ files:
99
112
  - examples/website_domain.rb
100
113
  - lib/dogviz.rb
101
114
  - lib/dogviz/version.rb
102
- - tests/test_sisvis_graph.rb
103
- - tests/test_sisvis_graphviz_rendering.rb
115
+ - tests/setup_tests.rb
116
+ - tests/svg_graph.rb
117
+ - tests/test_dogviz_functionally.rb
118
+ - tests/test_dogviz_graph.rb
119
+ - tests/test_dogviz_graphviz_rendering.rb
104
120
  homepage: https://github.com/damned/dogviz
105
121
  licenses:
106
122
  - MIT
data/Gemfile.lock DELETED
@@ -1,30 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- dogviz (0.0.3)
5
- ruby-graphviz (~> 1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- colorize (0.7.7)
11
- multi_json (1.8.4)
12
- rake (10.1.0)
13
- ruby-graphviz (1.2.2)
14
- simplecov (0.7.1)
15
- multi_json (~> 1.0)
16
- simplecov-html (~> 0.7.1)
17
- simplecov-html (0.7.1)
18
-
19
- PLATFORMS
20
- ruby
21
-
22
- DEPENDENCIES
23
- bundler (~> 1.10)
24
- colorize (~> 0)
25
- dogviz!
26
- rake (~> 10.0)
27
- simplecov (~> 0)
28
-
29
- BUNDLED WITH
30
- 1.10.6