model-graph 0.1.4

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.
@@ -0,0 +1,17 @@
1
+ class Post < ActiveRecord::Base
2
+ has_many :comments
3
+ has_one :author
4
+ has_and_belongs_to_many :categories
5
+ end
6
+
7
+ class Author < ActiveRecord::Base
8
+ # has_many :posts
9
+ end
10
+
11
+ class Comment < ActiveRecord::Base
12
+ belongs_to :post
13
+ end
14
+
15
+ class Category < ActiveRecord::Base
16
+ has_and_belongs_to_many :posts
17
+ end
data/examples/blog.rb ADDED
@@ -0,0 +1,35 @@
1
+ class Author < ActiveRecord::Base
2
+ has_many :posts
3
+ # has_many :favorite_authors
4
+ # has_many :users, :through => :favorite_authors, :class_name => 'User'
5
+ end
6
+
7
+ class Category < ActiveRecord::Base
8
+ has_and_belongs_to_many :posts
9
+ end
10
+
11
+ class Comment < ActiveRecord::Base
12
+ belongs_to :post
13
+ belongs_to :user
14
+ end
15
+
16
+ class FavoriteAuthor < ActiveRecord::Base
17
+ belongs_to :user
18
+ belongs_to :author
19
+ end
20
+
21
+ class Post < ActiveRecord::Base
22
+ has_many :comments
23
+ has_one :author
24
+ has_and_belongs_to_many :categories
25
+ end
26
+
27
+ class Theme < ActiveRecord::Base
28
+ belongs_to :user
29
+ end
30
+
31
+ class User < ActiveRecord::Base
32
+ has_many :comments
33
+ has_one :theme
34
+ has_many :favorite_authors
35
+ end
@@ -0,0 +1,17 @@
1
+ class Post < ActiveRecord::Base
2
+ has_many :comments
3
+ has_one :author
4
+ has_and_belongs_to_many :categories
5
+ end
6
+
7
+ class Author < ActiveRecord::Base
8
+ has_many :posts
9
+ end
10
+
11
+ class Comment < ActiveRecord::Base
12
+ belongs_to :post
13
+ end
14
+
15
+ class Category < ActiveRecord::Base
16
+ has_and_belongs_to_many :posts
17
+ end
data/examples/hello.rb ADDED
@@ -0,0 +1,6 @@
1
+ class Hello < ActiveRecord::Base # :nodoc:
2
+ belongs_to :world
3
+ end
4
+ class World < ActiveRecord::Base # :nodoc:
5
+ has_many :hellos
6
+ end
@@ -0,0 +1,36 @@
1
+ class Advertisement < ActiveRecord::Base # :nodoc:
2
+ belongs_to :issue
3
+ belongs_to :vendor
4
+ end
5
+ class Article < ActiveRecord::Base # :nodoc:
6
+ has_one :author
7
+ belongs_to :issue
8
+ end
9
+ class Author < ActiveRecord::Base # :nodoc:
10
+ has_many :articles
11
+ end
12
+ class Issue < ActiveRecord::Base # :nodoc:
13
+ has_one :theme
14
+ has_many :articles
15
+ has_many :advertisements
16
+ end
17
+ class Magazine < ActiveRecord::Base # :nodoc:
18
+ has_many :issues
19
+ has_many :articles, :through => :issues
20
+ has_many :subscriptions
21
+ has_many :subscribers, :through => :subscriptions
22
+ end
23
+ class Theme < ActiveRecord::Base # :nodoc:
24
+ belongs_to :issue
25
+ end
26
+ class Subscriber < ActiveRecord::Base # :nodoc:
27
+ has_many :subscriptions
28
+ has_many :magazines, :through => :subscriptions
29
+ end
30
+ class Subscription < ActiveRecord::Base # :nodoc:
31
+ belongs_to :subscriber
32
+ belongs_to :magazine
33
+ end
34
+ class Vendor < ActiveRecord::Base # :nodoc:
35
+ has_many :advertisements
36
+ end
@@ -0,0 +1,41 @@
1
+ class < ActiveRecord::Base
2
+ has_many
3
+ has_one
4
+ has_and_belongs_to_many
5
+ belongs_to
6
+ end
7
+
8
+ class Page < ActiveRecord::Base
9
+ has_many :content_parts
10
+ belongs_to :behavior
11
+ belongs_to :layout
12
+ end
13
+
14
+ class Behavior < ActiveRecord::Base
15
+ has_many :pages
16
+ has_one
17
+ has_and_belongs_to_many
18
+ belongs_to
19
+ end
20
+
21
+ class Layout < ActiveRecord::Base
22
+ has_many
23
+ has_one
24
+ has_and_belongs_to_many
25
+ belongs_to
26
+ end
27
+
28
+ class ContentPart < ActiveRecord::Base
29
+ has_many
30
+ has_one :filter
31
+ has_and_belongs_to_many
32
+ belongs_to :page
33
+ end
34
+
35
+ class Filter < ActiveRecord::Base
36
+ has_many
37
+ has_one
38
+ has_and_belongs_to_many
39
+ belongs_to :content_parts
40
+ end
41
+
data/lib/graph.rb ADDED
@@ -0,0 +1,71 @@
1
+ # An internal class to collect abstract nodes and edges and deliver them
2
+ # back when needed.
3
+ class Graph
4
+ attr_reader :name
5
+
6
+ # Holds information about nodes and edges that should be depicted on the
7
+ # UML-ish graph of the ActiveRecord model classes. The +name+ is optional
8
+ # and only serves to give the graph an internal name. If you had an
9
+ # application to combine model graphs from multiple applications, this
10
+ # might be useful.
11
+ def initialize(name="model_graph")
12
+ @name = name
13
+ @nodes = Hash.new # holds simple strings
14
+ @edges = Hash.new { |h,k| h[k] = Hash.new { |h2,k2| h2[k2] = Hash.new } }
15
+
16
+ # A hm B :as => Y gives edge A->B and implies B bt A
17
+ # C hm B :as => Y gives edge C->B and implies B bt A
18
+ # B bt Y :polymorphic => true no new information
19
+ end
20
+
21
+ # Create an unattached node in this graph.
22
+ def add_node(nodename, options="")
23
+ @nodes[nodename] = options
24
+ end
25
+
26
+ # Iterates over all the nodes previously added to this graph.
27
+ def nodes # :yields: nodestring
28
+ @nodes.each do |name,options|
29
+ yield "#{name} #{options}"
30
+ end
31
+ end
32
+
33
+ # Create a directed edge from one node to another. If an edge between
34
+ # nodes already exists in the opposite direction, the arrow will be
35
+ # attached to the other end of the existing edge.
36
+ def add_edge(fromnode, tonode, options={})
37
+ unless @edges[tonode].has_key? fromnode
38
+ options.each do |k,v|
39
+ @edges[fromnode][tonode][case k.to_s
40
+ when 'label' : 'taillabel'
41
+ when 'midlabel' : 'label'
42
+ when /^arrow(?:head|tail)?$/ : 'arrowhead'
43
+ else k
44
+ end] = v
45
+ end
46
+ else
47
+ # reverse sense and overload existing edge
48
+ options.each do |k,v|
49
+ @edges[tonode][fromnode][case k.to_s
50
+ when 'label' : 'headlabel'
51
+ when 'midlabel' : 'label'
52
+ when /^arrow(?:head|tail)?$/ : 'arrowtail'
53
+ else k
54
+ end] = v
55
+ end
56
+ end
57
+ end
58
+
59
+ # Iterates over all the DOT formatted edges with nodes having the most
60
+ # edges first and the edges without a constraint attribute before those
61
+ # that do.
62
+ def edges(options={}) # :yields: edgestring
63
+ @edges.sort { |a,b| b[1].length <=> a[1].length }.each do |(fromnode,nh)|
64
+ nh.sort_by { |(t,a)| (a.has_key?('constraint') ^ options[:constraints_first]) ? 1 : 0 }.each do |tonode,eh|
65
+ e = "#{fromnode} -> #{tonode} "
66
+ e << eh.inspect(options) unless eh.nil?
67
+ yield e
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1 @@
1
+ Dir[File.join(File.dirname(__FILE__), '**/*.rb')].sort.each { |lib| require lib }
@@ -0,0 +1,9 @@
1
+ module ModelGraph
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 4
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ModelGraphTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ # @graph = ModelGraph::Graph.new "tester"
7
+ end
8
+
9
+ def test_as_and_polymorphic
10
+ assert 'embarassingly incomplete'
11
+ end
12
+
13
+ end
@@ -0,0 +1,5 @@
1
+ require 'test/unit'
2
+ require 'lib/model_graph'
3
+
4
+ module ModelGraphTestHelper
5
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: model-graph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Rob Biedenharn
8
+ autorequire: model_graph
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-21 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "When run from the trunk of a Rails project, produces # {DOT}[http://www.graphviz.org/doc/info/lang.html] output which can be # rendered into a graph by programs such as dot and neato and viewed with # Graphviz (an {Open Source}[http://www.graphviz.org/License.php] viewer)."
17
+ email: Rob_Biedenharn@alum.MIT.edu
18
+ executables:
19
+ - model_graph
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - CHANGELOG
25
+ files:
26
+ - README
27
+ - CHANGELOG
28
+ - Rakefile
29
+ - bin/model_graph
30
+ - doc/classes
31
+ - doc/classes/ModelGraph
32
+ - doc/classes/ModelGraph/Graph.html
33
+ - doc/classes/ModelGraph/Graph.src
34
+ - doc/classes/ModelGraph/Graph.src/M000003.html
35
+ - doc/classes/ModelGraph/Graph.src/M000004.html
36
+ - doc/classes/ModelGraph/Graph.src/M000005.html
37
+ - doc/classes/ModelGraph/Graph.src/M000006.html
38
+ - doc/classes/ModelGraph/Graph.src/M000007.html
39
+ - doc/classes/ModelGraph.html
40
+ - doc/classes/ModelGraph.src
41
+ - doc/classes/ModelGraph.src/M000001.html
42
+ - doc/classes/ModelGraph.src/M000002.html
43
+ - doc/created.rid
44
+ - doc/dot
45
+ - doc/dot/f_0.dot
46
+ - doc/dot/f_0.png
47
+ - doc/dot/m_0_0.dot
48
+ - doc/dot/m_0_0.png
49
+ - doc/files
50
+ - doc/files/lib
51
+ - doc/files/model_graph_rb.html
52
+ - doc/fr_class_index.html
53
+ - doc/fr_file_index.html
54
+ - doc/fr_method_index.html
55
+ - doc/index.html
56
+ - doc/rdoc-style.css
57
+ - test/model_graph_test.rb
58
+ - test/test_helper.rb
59
+ - lib/graph.rb
60
+ - lib/model_graph
61
+ - lib/model_graph/version.rb
62
+ - lib/model_graph.rb
63
+ - examples/badblog.rb
64
+ - examples/blog.rb
65
+ - examples/goodblog.rb
66
+ - examples/hello.rb
67
+ - examples/magazine.rb
68
+ - examples/radiant.rb
69
+ has_rdoc: true
70
+ homepage: http://model-graph.rubyforge.org
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --quiet
74
+ - --title
75
+ - model_graph documentation
76
+ - --opname
77
+ - index.html
78
+ - --line-numbers
79
+ - --main
80
+ - README
81
+ - --inline-source
82
+ - --exclude
83
+ - ^(examples|extras)/
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ requirements: []
99
+
100
+ rubyforge_project: model-graph
101
+ rubygems_version: 1.1.1
102
+ signing_key:
103
+ specification_version: 2
104
+ summary: "When run from the trunk of a Rails project, produces # {DOT}[http://www.graphviz.org/doc/info/lang.html] output which can be # rendered into a graph by programs such as dot and neato and viewed with # Graphviz (an {Open Source}[http://www.graphviz.org/License.php] viewer)."
105
+ test_files: []
106
+