graph 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/History.txt CHANGED
@@ -1,3 +1,15 @@
1
+ === 2.0.1 / 2011-02-18
2
+
3
+ * 2 minor enhancements:
4
+
5
+ * Slightly improved output.
6
+ * Refactored Node and Edgue under Thingy.
7
+
8
+ * 2 bug fixes:
9
+
10
+ * Expanded out subcall to rake to include current load path
11
+ * Use the rake from the calling ruby process as the invoking process
12
+
1
13
  === 2.0.0 / 2010-12-24
2
14
 
3
15
  * 1 major enhancement:
data/README.txt CHANGED
@@ -12,6 +12,15 @@ rubygems, rake tasks, homebrew ports, mac ports, and freebsd ports,
12
12
  coloring leaf nodes blue, outdated nodes red, and outdated leaf nodes
13
13
  purple (red+blue).
14
14
 
15
+ OSX quick tip:
16
+
17
+ % sudo gem install graph
18
+ % sudo brew install graphviz
19
+ % gem unpack graph
20
+ % cd graph*
21
+ % rake gallery
22
+ % open gallery/*.png
23
+
15
24
  == FEATURES/PROBLEMS:
16
25
 
17
26
  * Very clean DSL interface and API.
data/lib/graph.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  #!/usr/local/bin/ruby -w
2
2
 
3
+ require "enumerator"
4
+
3
5
  ##
4
6
  # Graph models directed graphs and subgraphs and outputs in graphviz's
5
7
  # dot format.
6
8
 
7
9
  class Graph
8
- VERSION = "2.0.0" # :nodoc:
10
+ VERSION = "2.0.1" # :nodoc:
9
11
 
10
12
  LIGHT_COLORS = %w(gray lightblue lightcyan lightgray lightpink
11
13
  lightslategray lightsteelblue white)
@@ -228,7 +230,7 @@ class Graph
228
230
 
229
231
  def save path, type = nil
230
232
  File.open "#{path}.dot", "w" do |f|
231
- f.write self.to_s
233
+ f.puts self.to_s
232
234
  end
233
235
  system "dot -T#{type} #{path}.dot > #{path}.#{type}" if type
234
236
  end
@@ -282,7 +284,7 @@ class Graph
282
284
  end
283
285
 
284
286
  nodes.each do |name, node|
285
- result << " #{node};" if graph or not node.attributes.empty?
287
+ result << " #{node};" if graph or node.attributes?
286
288
  end
287
289
 
288
290
  edges.each do |from, deps|
@@ -332,35 +334,58 @@ class Graph
332
334
  end
333
335
  end
334
336
 
335
- ##
336
- # An edge in a graph.
337
-
338
- class Edge < Struct.new :graph, :from, :to, :attributes
339
-
340
- ##
341
- # Create a new edge in +graph+ from +from+ to +to+.
337
+ class Thingy < Struct.new :graph, :attributes
338
+ def initialize graph
339
+ super graph, []
340
+ end
342
341
 
343
- def initialize graph, from, to
344
- super graph, from, to, []
342
+ def initialize_copy other # :nodoc:
343
+ super
344
+ self.attributes = other.attributes.dup
345
345
  end
346
346
 
347
347
  ##
348
- # Shortcut method to set the label attribute on an edge.
348
+ # Shortcut method to set the label attribute.
349
349
 
350
350
  def label name
351
+ attributes.reject! { |s| s =~ /^label =/ }
351
352
  attributes << "label = \"#{name}\""
352
353
  self
353
354
  end
354
355
 
356
+ ##
357
+ # Does this thing have attributes?
358
+
359
+ def attributes?
360
+ not self.attributes.empty?
361
+ end
362
+ end
363
+
364
+ ##
365
+ # An edge in a graph.
366
+
367
+ class Edge < Thingy
368
+
369
+ attr_accessor :from, :to
370
+
371
+ ##
372
+ # Create a new edge in +graph+ from +from+ to +to+.
373
+
374
+ def initialize graph, from, to
375
+ super graph
376
+ self.from = from
377
+ self.to = to
378
+ end
379
+
355
380
  ##
356
381
  # Returns the edge in dot syntax.
357
382
 
358
383
  def to_s
359
384
  fromto = "%p -> %p" % [from.name, to.name]
360
- if attributes.empty? then
361
- fromto
362
- else
385
+ if self.attributes? then
363
386
  "%-20s [ %-20s ]" % [fromto, attributes.join(',')]
387
+ else
388
+ fromto
364
389
  end
365
390
  end
366
391
  end
@@ -368,20 +393,16 @@ class Graph
368
393
  ##
369
394
  # Nodes in the graph.
370
395
 
371
- class Node < Struct.new :graph, :name, :attributes
396
+ class Node < Thingy
397
+
398
+ attr_accessor :name
372
399
 
373
400
  ##
374
401
  # Create a new Node. Takes a parent graph and a name.
375
402
 
376
403
  def initialize graph, name
377
- super graph, name, []
378
- end
379
-
380
- ##
381
- # Shortcut method to set the node's label.
382
-
383
- def label name
384
- attributes << "label = #{name.inspect}"
404
+ super graph
405
+ self.name = name
385
406
  end
386
407
 
387
408
  ##
@@ -406,10 +427,10 @@ class Graph
406
427
  # Returns the node in dot syntax.
407
428
 
408
429
  def to_s
409
- if attributes.empty? then
410
- "#{name.inspect}"
411
- else
430
+ if self.attributes? then
412
431
  "%-20p [ %-20s ]" % [name, attributes.join(',')]
432
+ else
433
+ "#{name.inspect}"
413
434
  end
414
435
  end
415
436
  end
data/lib/rake_analyzer.rb CHANGED
@@ -7,7 +7,9 @@ class RakeAnalyzer < DepAnalyzer
7
7
  boxes
8
8
 
9
9
  current = nil
10
- `rake -P -s`.each_line do |line|
10
+ rake = Gem.bin_path('rake', 'rake') rescue 'rake'
11
+
12
+ `#{Gem.ruby} -I#{$:.join File::PATH_SEPARATOR} -S #{rake} -P -s`.each_line do |line|
11
13
  case line
12
14
  when /^rake (.+)/
13
15
  name = $1
data/test/test_graph.rb CHANGED
@@ -206,7 +206,7 @@ g_s = "subgraph subgraph
206
206
 
207
207
  graph.save(path, type)
208
208
 
209
- assert_equal graph.to_s, File.read("#{path}.dot")
209
+ assert_equal graph.to_s + "\n", File.read("#{path}.dot")
210
210
  expected = ["dot -T#{type} #{path}.dot > #{path}.png"] if type
211
211
  assert_equal expected, $x
212
212
  ensure
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graph
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 13
5
+ prerelease:
5
6
  segments:
6
7
  - 2
7
8
  - 0
8
- - 0
9
- version: 2.0.0
9
+ - 1
10
+ version: 2.0.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ryan Davis
@@ -35,35 +36,39 @@ cert_chain:
35
36
  FBHgymkyj/AOSqKRIpXPhjC6
36
37
  -----END CERTIFICATE-----
37
38
 
38
- date: 2010-12-24 00:00:00 -08:00
39
+ date: 2011-02-18 00:00:00 -08:00
39
40
  default_executable:
40
41
  dependencies:
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: minitest
43
44
  prerelease: false
44
45
  requirement: &id001 !ruby/object:Gem::Requirement
46
+ none: false
45
47
  requirements:
46
48
  - - ">="
47
49
  - !ruby/object:Gem::Version
50
+ hash: 11
48
51
  segments:
49
52
  - 2
50
53
  - 0
51
- - 0
52
- version: 2.0.0
54
+ - 2
55
+ version: 2.0.2
53
56
  type: :development
54
57
  version_requirements: *id001
55
58
  - !ruby/object:Gem::Dependency
56
59
  name: hoe
57
60
  prerelease: false
58
61
  requirement: &id002 !ruby/object:Gem::Requirement
62
+ none: false
59
63
  requirements:
60
64
  - - ">="
61
65
  - !ruby/object:Gem::Version
66
+ hash: 41
62
67
  segments:
63
68
  - 2
64
- - 8
65
- - 0
66
- version: 2.8.0
69
+ - 9
70
+ - 1
71
+ version: 2.9.1
67
72
  type: :development
68
73
  version_requirements: *id002
69
74
  description: |-
@@ -74,6 +79,15 @@ description: |-
74
79
  rubygems, rake tasks, homebrew ports, mac ports, and freebsd ports,
75
80
  coloring leaf nodes blue, outdated nodes red, and outdated leaf nodes
76
81
  purple (red+blue).
82
+
83
+ OSX quick tip:
84
+
85
+ % sudo gem install graph
86
+ % sudo brew install graphviz
87
+ % gem unpack graph
88
+ % cd graph*
89
+ % rake gallery
90
+ % open gallery/*.png
77
91
  email:
78
92
  - ryand-ruby@zenspider.com
79
93
  executables:
@@ -106,6 +120,7 @@ files:
106
120
  - lib/rubygems_analyzer.rb
107
121
  - lib/rubygems_plugin.rb
108
122
  - test/test_graph.rb
123
+ - .gemtest
109
124
  has_rdoc: true
110
125
  homepage: http://rubyforge.org/projects/seattlerb
111
126
  licenses: []
@@ -117,23 +132,27 @@ rdoc_options:
117
132
  require_paths:
118
133
  - lib
119
134
  required_ruby_version: !ruby/object:Gem::Requirement
135
+ none: false
120
136
  requirements:
121
137
  - - ">="
122
138
  - !ruby/object:Gem::Version
139
+ hash: 3
123
140
  segments:
124
141
  - 0
125
142
  version: "0"
126
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
+ none: false
127
145
  requirements:
128
146
  - - ">="
129
147
  - !ruby/object:Gem::Version
148
+ hash: 3
130
149
  segments:
131
150
  - 0
132
151
  version: "0"
133
152
  requirements: []
134
153
 
135
154
  rubyforge_project: seattlerb
136
- rubygems_version: 1.3.6
155
+ rubygems_version: 1.4.2
137
156
  signing_key:
138
157
  specification_version: 3
139
158
  summary: Graph is a type of hash that outputs in graphviz's dot format
metadata.gz.sig CHANGED
Binary file