dm-visualizer 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.
- data/.rspec +1 -0
- data/ChangeLog.md +11 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +1 -3
- data/README.md +11 -8
- data/Rakefile +14 -36
- data/dm-visualizer.gemspec +11 -96
- data/gemspec.yml +23 -0
- data/lib/dm-visualizer/graphviz.rb +5 -5
- data/lib/dm-visualizer/project.rb +61 -50
- data/lib/dm-visualizer/rake/graphviz_task.rb +55 -23
- data/lib/dm-visualizer/rake/rails/tasks.rb +9 -2
- data/lib/dm-visualizer/rake/task.rb +12 -0
- data/lib/dm-visualizer/visualization.rb +2 -9
- data/spec/dm_visualizer_spec.rb +0 -3
- data/spec/spec_helper.rb +1 -6
- data/spec/visualization_spec.rb +5 -7
- metadata +70 -96
- data/.gitignore +0 -9
- data/.specopts +0 -1
- data/VERSION +0 -1
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
### 0.2.0 / 2011-02-09
|
2
|
+
|
3
|
+
* Require dm-core >= 1.0.0.
|
4
|
+
* {DataMapper::Visualizer::Rake::GraphVizTask} now defines tasks for
|
5
|
+
generating Relational and Schema diagrams, with PNG and SVG output.
|
6
|
+
* Fixed a bug in {DataMapper::Visualizer::Rake::Rails::Tasks} which
|
7
|
+
prevented dm-visualizer from working in newer dm-rails applications.
|
8
|
+
* Filter-out foreign-key columns in
|
9
|
+
{DataMapper::Visualizer::Project#each_property}.
|
10
|
+
* Tested against dm-core 1.0.2 and 1.1.0.
|
11
|
+
|
1
12
|
### 0.1.0 / 2010-05-27
|
2
13
|
|
3
14
|
* Initial release:
|
data/Gemfile
ADDED
data/LICENSE.txt
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
Copyright (c) 2010 Hal Brodigan
|
1
|
+
Copyright (c) 2010-2011 Hal Brodigan
|
3
2
|
|
4
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
5
4
|
a copy of this software and associated documentation files (the
|
@@ -19,4 +18,3 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
19
18
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
19
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
20
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
* [github.com/postmodern/dm-visualizer](http://github.com/postmodern/dm-visualizer/)
|
4
4
|
* [github.com/postmodern/dm-visualizer/issues](http://github.com/postmodern/dm-visualizer/issues)
|
5
|
-
*
|
5
|
+
* [Email](postmodern.mod3 at gmail.com)
|
6
6
|
|
7
7
|
## Description
|
8
8
|
|
@@ -14,13 +14,15 @@ DataMapper based Ruby project.
|
|
14
14
|
|
15
15
|
* Safely loads the models of a project.
|
16
16
|
* Supports using [Gem Bundler](http://gembundler.com/).
|
17
|
-
* Generates GraphViz diagrams for a project
|
18
|
-
*
|
19
|
-
*
|
17
|
+
* Generates GraphViz diagrams for a project:
|
18
|
+
* Supports generating Relational and Schema diagrams.
|
19
|
+
* Provides PNG and SVG output.
|
20
|
+
* Provides Rake tasks for both Ruby libraries and dm-rails apps.
|
21
|
+
* Supports DataMapper >= 1.0.0.
|
20
22
|
|
21
23
|
## Examples
|
22
24
|
|
23
|
-
Add the `dm:doc:graphviz` rake
|
25
|
+
Add the `dm:doc:graphviz` rake tasks to a Ruby library:
|
24
26
|
|
25
27
|
require 'dm-visualizer/rake/graphviz_task'
|
26
28
|
DataMapper::Visualizer::Rake::GraphVizTask.new(
|
@@ -28,7 +30,7 @@ Add the `dm:doc:graphviz` rake task to a Ruby library:
|
|
28
30
|
:require => ['my_library/models']
|
29
31
|
)
|
30
32
|
|
31
|
-
Add the `db:doc:graphviz` rake
|
33
|
+
Add the `db:doc:graphviz` rake tasks to a [dm-rails](http://github.com/datamapper/dm-rails) app:
|
32
34
|
|
33
35
|
require 'dm-visualizer/rake/rails/graphviz_task'
|
34
36
|
DataMapper::Visualizer::Rake::Rails::GraphVizTask.new
|
@@ -36,7 +38,7 @@ Add the `db:doc:graphviz` rake task to a Rails3 / [dm-rails](http://github.com/d
|
|
36
38
|
## Requirements
|
37
39
|
|
38
40
|
* [ruby-graphviz](http://rubygems.org/gems/ruby-graphviz) >= 0.9.10
|
39
|
-
* [dm-core](http://github.com/datamapper/dm-core) >= 0.
|
41
|
+
* [dm-core](http://github.com/datamapper/dm-core) >= 1.0.0
|
40
42
|
|
41
43
|
## Install
|
42
44
|
|
@@ -44,5 +46,6 @@ Add the `db:doc:graphviz` rake task to a Rails3 / [dm-rails](http://github.com/d
|
|
44
46
|
|
45
47
|
## License
|
46
48
|
|
47
|
-
|
49
|
+
Copyright (c) 2010-2011 Hal Brodigan
|
48
50
|
|
51
|
+
See {file:LICENSE.txt} for license information.
|
data/Rakefile
CHANGED
@@ -1,44 +1,22 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
2
|
+
require 'bundler'
|
3
3
|
|
4
4
|
begin
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
gem.description = %Q{DataMapper Visualizer is both a library and a command-line utility for visualizing the Models, Properties and Relationships defined in a DataMapper based Ruby project.}
|
11
|
-
gem.email = 'postmodern.mod3@gmail.com'
|
12
|
-
gem.homepage = 'http://github.com/postmodern/dm-visualizer'
|
13
|
-
gem.authors = ['Postmodern']
|
14
|
-
gem.add_dependency 'ruby-graphviz', '>= 0.9.10'
|
15
|
-
gem.add_dependency 'dm-core', '>= 0.10.2'
|
16
|
-
gem.add_dependency 'thor', '>= 0.13.4'
|
17
|
-
gem.add_development_dependency 'rspec', '~> 1.3.0'
|
18
|
-
gem.add_development_dependency 'yard', '~> 0.5.3'
|
19
|
-
gem.has_rdoc = 'yard'
|
20
|
-
end
|
21
|
-
Jeweler::GemcutterTasks.new
|
22
|
-
rescue LoadError
|
23
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
5
|
+
Bundler.setup(:development, :doc)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
STDERR.puts e.message
|
8
|
+
STDERR.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
24
10
|
end
|
25
11
|
|
26
|
-
require '
|
27
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
28
|
-
spec.libs += ['lib', 'spec']
|
29
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
30
|
-
spec.spec_opts = ['--options', '.specopts']
|
31
|
-
end
|
12
|
+
require 'rake'
|
32
13
|
|
33
|
-
|
34
|
-
|
14
|
+
require 'ore/tasks'
|
15
|
+
Ore::Tasks.new
|
35
16
|
|
36
|
-
|
37
|
-
|
17
|
+
require 'rspec/core/rake_task'
|
18
|
+
RSpec::Core::RakeTask.new
|
19
|
+
task :default => :spec
|
38
20
|
|
39
|
-
|
40
|
-
|
41
|
-
task :yard do
|
42
|
-
abort "YARD is not available. In order to run yard, you must: gem install yard"
|
43
|
-
end
|
44
|
-
end
|
21
|
+
require 'yard'
|
22
|
+
YARD::Rake::YardocTask.new
|
data/dm-visualizer.gemspec
CHANGED
@@ -1,100 +1,15 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
"
|
17
|
-
"LICENSE.txt",
|
18
|
-
"README.md"
|
19
|
-
]
|
20
|
-
s.files = [
|
21
|
-
".gitignore",
|
22
|
-
".specopts",
|
23
|
-
".yardopts",
|
24
|
-
"ChangeLog.md",
|
25
|
-
"LICENSE.txt",
|
26
|
-
"README.md",
|
27
|
-
"Rakefile",
|
28
|
-
"VERSION",
|
29
|
-
"dm-visualizer.gemspec",
|
30
|
-
"lib/dm-visualizer.rb",
|
31
|
-
"lib/dm-visualizer/graphviz.rb",
|
32
|
-
"lib/dm-visualizer/project.rb",
|
33
|
-
"lib/dm-visualizer/rake/graphviz_task.rb",
|
34
|
-
"lib/dm-visualizer/rake/rails/graphviz_task.rb",
|
35
|
-
"lib/dm-visualizer/rake/rails/tasks.rb",
|
36
|
-
"lib/dm-visualizer/rake/task.rb",
|
37
|
-
"lib/dm-visualizer/visualization.rb",
|
38
|
-
"spec/dm_visualizer_spec.rb",
|
39
|
-
"spec/helpers/project.rb",
|
40
|
-
"spec/helpers/projects/library/lib/blog.rb",
|
41
|
-
"spec/helpers/projects/library/lib/blog/comment.rb",
|
42
|
-
"spec/helpers/projects/library/lib/blog/post.rb",
|
43
|
-
"spec/helpers/projects/library/lib/blog/user.rb",
|
44
|
-
"spec/helpers/projects/rails/app/models/comment.rb",
|
45
|
-
"spec/helpers/projects/rails/app/models/post.rb",
|
46
|
-
"spec/helpers/projects/rails/app/models/user.rb",
|
47
|
-
"spec/project_examples.rb",
|
48
|
-
"spec/project_spec.rb",
|
49
|
-
"spec/spec_helper.rb",
|
50
|
-
"spec/visualization_spec.rb"
|
51
|
-
]
|
52
|
-
s.has_rdoc = %q{yard}
|
53
|
-
s.homepage = %q{http://github.com/postmodern/dm-visualizer}
|
54
|
-
s.licenses = ["MIT"]
|
55
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
56
|
-
s.require_paths = ["lib"]
|
57
|
-
s.rubygems_version = %q{1.3.7}
|
58
|
-
s.summary = %q{Visualizes the Models, Properties and Relationships defined in a DataMapper based Ruby project.}
|
59
|
-
s.test_files = [
|
60
|
-
"spec/project_spec.rb",
|
61
|
-
"spec/spec_helper.rb",
|
62
|
-
"spec/visualization_spec.rb",
|
63
|
-
"spec/project_examples.rb",
|
64
|
-
"spec/helpers/project.rb",
|
65
|
-
"spec/helpers/projects/library/lib/blog.rb",
|
66
|
-
"spec/helpers/projects/library/lib/blog/post.rb",
|
67
|
-
"spec/helpers/projects/library/lib/blog/user.rb",
|
68
|
-
"spec/helpers/projects/library/lib/blog/comment.rb",
|
69
|
-
"spec/helpers/projects/rails/app/models/post.rb",
|
70
|
-
"spec/helpers/projects/rails/app/models/user.rb",
|
71
|
-
"spec/helpers/projects/rails/app/models/comment.rb",
|
72
|
-
"spec/dm_visualizer_spec.rb"
|
73
|
-
]
|
74
|
-
|
75
|
-
if s.respond_to? :specification_version then
|
76
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
77
|
-
s.specification_version = 3
|
78
|
-
|
79
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
80
|
-
s.add_runtime_dependency(%q<ruby-graphviz>, [">= 0.9.10"])
|
81
|
-
s.add_runtime_dependency(%q<dm-core>, [">= 0.10.2"])
|
82
|
-
s.add_runtime_dependency(%q<thor>, [">= 0.13.4"])
|
83
|
-
s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
|
84
|
-
s.add_development_dependency(%q<yard>, ["~> 0.5.3"])
|
85
|
-
else
|
86
|
-
s.add_dependency(%q<ruby-graphviz>, [">= 0.9.10"])
|
87
|
-
s.add_dependency(%q<dm-core>, [">= 0.10.2"])
|
88
|
-
s.add_dependency(%q<thor>, [">= 0.13.4"])
|
89
|
-
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
90
|
-
s.add_dependency(%q<yard>, ["~> 0.5.3"])
|
91
|
-
end
|
92
|
-
else
|
93
|
-
s.add_dependency(%q<ruby-graphviz>, [">= 0.9.10"])
|
94
|
-
s.add_dependency(%q<dm-core>, [">= 0.10.2"])
|
95
|
-
s.add_dependency(%q<thor>, [">= 0.13.4"])
|
96
|
-
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
97
|
-
s.add_dependency(%q<yard>, ["~> 0.5.3"])
|
3
|
+
begin
|
4
|
+
Ore::Specification.new do |gemspec|
|
5
|
+
# custom logic here
|
6
|
+
end
|
7
|
+
rescue NameError
|
8
|
+
begin
|
9
|
+
require 'ore/specification'
|
10
|
+
retry
|
11
|
+
rescue LoadError
|
12
|
+
STDERR.puts "The 'dm-visualizer.gemspec' file requires Ore."
|
13
|
+
STDERR.puts "Run `gem install ore-core` to install Ore."
|
98
14
|
end
|
99
15
|
end
|
100
|
-
|
data/gemspec.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
name: dm-visualizer
|
2
|
+
version: 0.2.0
|
3
|
+
summary:
|
4
|
+
Visualizes the Models, Properties and Relationships defined in a
|
5
|
+
DataMapper based Ruby project.
|
6
|
+
description:
|
7
|
+
DataMapper Visualizer is both a library and a command-line utility for
|
8
|
+
visualizing the Models, Properties and Relationships defined in a
|
9
|
+
DataMapper based Ruby project.
|
10
|
+
|
11
|
+
license: MIT
|
12
|
+
authors: Postmodern
|
13
|
+
email: postmodern.mod3@gmail.com
|
14
|
+
homepage: http://github.com/postmodern/dm-visualizer
|
15
|
+
has_yard: true
|
16
|
+
|
17
|
+
dependencies:
|
18
|
+
ruby-graphviz: >= 0.9.10
|
19
|
+
dm-core: >= 1.0.0
|
20
|
+
|
21
|
+
development_dependencies:
|
22
|
+
bundler: ~> 1.0.0
|
23
|
+
yard: ~> 0.6.0
|
@@ -19,7 +19,7 @@ module DataMapper
|
|
19
19
|
# The output file
|
20
20
|
attr_accessor :file
|
21
21
|
|
22
|
-
# The output file format (`:
|
22
|
+
# The output file format (`:svg`)
|
23
23
|
attr_accessor :format
|
24
24
|
|
25
25
|
# The colors to use
|
@@ -37,7 +37,7 @@ module DataMapper
|
|
37
37
|
# @option options [String] :file
|
38
38
|
# The output file path.
|
39
39
|
#
|
40
|
-
# @option options [Symbol] :format (:
|
40
|
+
# @option options [Symbol] :format (:svg)
|
41
41
|
# The format of the generated graph.
|
42
42
|
#
|
43
43
|
# @option options [Hash] :colors
|
@@ -51,7 +51,7 @@ module DataMapper
|
|
51
51
|
def initialize(options={})
|
52
52
|
super(options)
|
53
53
|
|
54
|
-
@format = :
|
54
|
+
@format = :svg
|
55
55
|
|
56
56
|
@colors = {
|
57
57
|
:one_to_many => 'blue',
|
@@ -111,8 +111,8 @@ module DataMapper
|
|
111
111
|
"#{property_name(property)}: #{property_type_name(property)}"
|
112
112
|
end
|
113
113
|
|
114
|
-
foreign_keys = project.each_foreign_key(model).map do |key,
|
115
|
-
"#{foreign_key_name(key)}: #{model_name(
|
114
|
+
foreign_keys = project.each_foreign_key(model).map do |key,value|
|
115
|
+
"#{foreign_key_name(key)}: #{model_name(value)}"
|
116
116
|
end
|
117
117
|
|
118
118
|
columns = (properties + foreign_keys)
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'set'
|
2
2
|
require 'dm-core'
|
3
3
|
|
4
|
-
require 'enumerator'
|
5
|
-
|
6
4
|
module DataMapper
|
7
5
|
module Visualizer
|
8
6
|
#
|
@@ -31,7 +29,7 @@ module DataMapper
|
|
31
29
|
# @option options [Array] :include
|
32
30
|
# The directories to include into the `$LOAD_PATH` global variable.
|
33
31
|
#
|
34
|
-
# @option options [
|
32
|
+
# @option options [Enumerable, Symbol, String, Boolean] :bundle
|
35
33
|
# Specifies which groups of dependencies to activate using Bundler.
|
36
34
|
#
|
37
35
|
# @option options [Array] :require
|
@@ -41,7 +39,7 @@ module DataMapper
|
|
41
39
|
# The path globs to require.
|
42
40
|
#
|
43
41
|
def initialize(options={})
|
44
|
-
@bundle =
|
42
|
+
@bundle = Set[]
|
45
43
|
@include_dirs = Set[]
|
46
44
|
@require_paths = Set[]
|
47
45
|
@require_globs = Set[]
|
@@ -52,12 +50,15 @@ module DataMapper
|
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
case options[:bundle]
|
54
|
+
when String, Symbol
|
55
|
+
@bundle << options[:bundle].to_sym
|
56
|
+
when Enumerable
|
58
57
|
options[:bundle].each do |group|
|
59
58
|
@bundle << group.to_sym
|
60
59
|
end
|
60
|
+
when true
|
61
|
+
@bundle << :default
|
61
62
|
end
|
62
63
|
|
63
64
|
if options[:require]
|
@@ -81,15 +82,15 @@ module DataMapper
|
|
81
82
|
|
82
83
|
begin
|
83
84
|
require 'bundler'
|
84
|
-
rescue LoadError
|
85
|
+
rescue LoadError
|
85
86
|
log "Gemfile exists, but bundler is not installed"
|
86
87
|
log "Run `gem install bundler` to install bundler."
|
87
88
|
end
|
88
89
|
|
89
90
|
begin
|
90
91
|
Bundler.setup(*@bundle)
|
91
|
-
rescue Bundler::BundleError =>
|
92
|
-
log
|
92
|
+
rescue Bundler::BundleError => error
|
93
|
+
log error.message
|
93
94
|
log "Run `bundle install` to install missing gems"
|
94
95
|
end
|
95
96
|
|
@@ -108,7 +109,7 @@ module DataMapper
|
|
108
109
|
end
|
109
110
|
|
110
111
|
# use Bundler if a Gemfile is present
|
111
|
-
bundle!
|
112
|
+
bundle! unless @bundle.empty?
|
112
113
|
|
113
114
|
return true
|
114
115
|
end
|
@@ -135,9 +136,9 @@ module DataMapper
|
|
135
136
|
@require_paths.each do |path|
|
136
137
|
begin
|
137
138
|
require path
|
138
|
-
rescue LoadError =>
|
139
|
+
rescue LoadError => error
|
139
140
|
log "dm-visualizer: unable to load #{path}"
|
140
|
-
log "dm-visualizer: #{
|
141
|
+
log "dm-visualizer: #{error.message}"
|
141
142
|
end
|
142
143
|
end
|
143
144
|
|
@@ -148,9 +149,9 @@ module DataMapper
|
|
148
149
|
|
149
150
|
begin
|
150
151
|
require relative_path
|
151
|
-
rescue LoadError =>
|
152
|
+
rescue LoadError => error
|
152
153
|
log "dm-visualizer: unable to load #{relative_path} from #{dir}"
|
153
|
-
log "dm-visualizer: #{
|
154
|
+
log "dm-visualizer: #{error.message}"
|
154
155
|
end
|
155
156
|
end
|
156
157
|
end
|
@@ -195,9 +196,7 @@ module DataMapper
|
|
195
196
|
# If no block is given, an Enumerator object will be returned.
|
196
197
|
#
|
197
198
|
def each_model_inheritence
|
198
|
-
unless block_given?
|
199
|
-
return Enumerator.new(self,:each_model_inheritence)
|
200
|
-
end
|
199
|
+
return enum_for(:each_model_inheritence) unless block_given?
|
201
200
|
|
202
201
|
each_model do |model|
|
203
202
|
direct_ancestor = model.ancestors[1]
|
@@ -208,32 +207,6 @@ module DataMapper
|
|
208
207
|
end
|
209
208
|
end
|
210
209
|
|
211
|
-
#
|
212
|
-
# Enumerates over each DataMapper property from a given model.
|
213
|
-
#
|
214
|
-
# @param [DataMapper::Model] model
|
215
|
-
# The given model.
|
216
|
-
#
|
217
|
-
# @yield [property]
|
218
|
-
# The given block will be passed every property from the given
|
219
|
-
# model.
|
220
|
-
#
|
221
|
-
# @yieldparam [DataMapper::Property] property
|
222
|
-
# The property.
|
223
|
-
#
|
224
|
-
# @return [Enumerator]
|
225
|
-
# If no block is given, an Enumerator object will be returned.
|
226
|
-
#
|
227
|
-
def each_property(model)
|
228
|
-
unless block_given?
|
229
|
-
return Enumerator.new(self,:each_property,model)
|
230
|
-
end
|
231
|
-
|
232
|
-
model.properties.each do |property|
|
233
|
-
yield property
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
210
|
#
|
238
211
|
# Enumerates over every foreign-key in a given model.
|
239
212
|
#
|
@@ -254,11 +227,14 @@ module DataMapper
|
|
254
227
|
# If no block is given, an Enumerator object will be returned.
|
255
228
|
#
|
256
229
|
def each_foreign_key(model)
|
257
|
-
unless block_given?
|
258
|
-
|
259
|
-
|
230
|
+
return enum_for(:each_foreign_key,model) unless block_given?
|
231
|
+
|
232
|
+
# XXX: in dm-core 1.1.0, `Model#relationships` returns a
|
233
|
+
# `DataMapper::RelationshipSet`, instead of a `Mash`, which does
|
234
|
+
# not provide the `each_value` method.
|
235
|
+
model.relationships.each do |*args|
|
236
|
+
relationship = args.last
|
260
237
|
|
261
|
-
model.relationships.each_value do |relationship|
|
262
238
|
next if relationship.respond_to?(:through)
|
263
239
|
|
264
240
|
case relationship
|
@@ -270,6 +246,36 @@ module DataMapper
|
|
270
246
|
end
|
271
247
|
end
|
272
248
|
|
249
|
+
#
|
250
|
+
# Enumerates over each DataMapper property from a given model.
|
251
|
+
#
|
252
|
+
# @param [DataMapper::Model] model
|
253
|
+
# The given model.
|
254
|
+
#
|
255
|
+
# @yield [property]
|
256
|
+
# The given block will be passed every property from the given
|
257
|
+
# model.
|
258
|
+
#
|
259
|
+
# @yieldparam [DataMapper::Property] property
|
260
|
+
# The property.
|
261
|
+
#
|
262
|
+
# @return [Enumerator]
|
263
|
+
# If no block is given, an Enumerator object will be returned.
|
264
|
+
#
|
265
|
+
def each_property(model)
|
266
|
+
return enum_for(:each_property,model) unless block_given?
|
267
|
+
|
268
|
+
foreign_keys = Set[]
|
269
|
+
|
270
|
+
each_foreign_key(model) do |name,parent_model|
|
271
|
+
foreign_keys << name
|
272
|
+
end
|
273
|
+
|
274
|
+
model.properties.each do |property|
|
275
|
+
yield property unless foreign_keys.include?(property.name)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
273
279
|
#
|
274
280
|
# Enumerates over each DataMapper relationship between each model.
|
275
281
|
#
|
@@ -287,10 +293,15 @@ module DataMapper
|
|
287
293
|
# If no block is given, an Enumerator object will be returned.
|
288
294
|
#
|
289
295
|
def each_relationship
|
290
|
-
return
|
296
|
+
return enum_for(:each_relationship) unless block_given?
|
291
297
|
|
292
298
|
each_model do |model|
|
293
|
-
|
299
|
+
# XXX: in dm-core 1.1.0, `Model#relationships` returns a
|
300
|
+
# `DataMapper::RelationshipSet`, instead of a `Mash`, which does
|
301
|
+
# not provide the `each_value` method.
|
302
|
+
model.relationships.each do |*args|
|
303
|
+
relationship = args.last
|
304
|
+
|
294
305
|
unless relationship.respond_to?(:through)
|
295
306
|
yield relationship, model
|
296
307
|
end
|
@@ -1,16 +1,24 @@
|
|
1
1
|
require 'dm-visualizer/rake/task'
|
2
2
|
require 'dm-visualizer/graphviz'
|
3
3
|
|
4
|
+
require 'set'
|
5
|
+
|
4
6
|
module DataMapper
|
5
7
|
module Visualizer
|
6
8
|
module Rake
|
7
9
|
class GraphVizTask < Task
|
8
10
|
|
9
|
-
# The
|
10
|
-
|
11
|
+
# The types of GraphViz diagrams.
|
12
|
+
DIAGRAMS = Set[:relational, :schema]
|
13
|
+
|
14
|
+
# The image formats for GraphViz diagrams.
|
15
|
+
FORMATS = Set[:png, :svg]
|
16
|
+
|
17
|
+
# The types of diagrams to generate.
|
18
|
+
attr_reader :diagrams
|
11
19
|
|
12
|
-
# The
|
13
|
-
attr_reader :
|
20
|
+
# The formats of the diagrams to generate.
|
21
|
+
attr_reader :formats
|
14
22
|
|
15
23
|
#
|
16
24
|
# Creates a new `dm:doc:graphviz` task.
|
@@ -18,6 +26,18 @@ module DataMapper
|
|
18
26
|
# @param [Hash] options
|
19
27
|
# Additional options.
|
20
28
|
#
|
29
|
+
# @option options [Boolean] :relational
|
30
|
+
# Specifies whether to generate a relational diagram.
|
31
|
+
#
|
32
|
+
# @option options [Boolean] :schema
|
33
|
+
# Specifies whether to generate a schema diagram.
|
34
|
+
#
|
35
|
+
# @option options [Boolean] :png
|
36
|
+
# Specifies whether to generate a PNG image.
|
37
|
+
#
|
38
|
+
# @option options [Boolean] :svg
|
39
|
+
# Specifies whether to generate a SVG image.
|
40
|
+
#
|
21
41
|
# @yield [task]
|
22
42
|
# The given block will be passed the newly created task.
|
23
43
|
#
|
@@ -26,38 +46,50 @@ module DataMapper
|
|
26
46
|
#
|
27
47
|
# @see GraphViz.new
|
28
48
|
#
|
29
|
-
def initialize(options={})
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
49
|
+
def initialize(options={},&block)
|
50
|
+
extract_options = lambda { |keys|
|
51
|
+
if keys.any? { |key| options[key] }
|
52
|
+
keys.select { |key| options.delete(key) }
|
53
|
+
else
|
54
|
+
keys
|
55
|
+
end
|
56
|
+
}
|
34
57
|
|
35
|
-
@
|
36
|
-
|
37
|
-
:file => 'doc/schema_diagram'
|
38
|
-
))
|
58
|
+
@diagrams = extract_options[DIAGRAMS]
|
59
|
+
@formats = extract_options[FORMATS]
|
39
60
|
|
40
|
-
super
|
61
|
+
super(options,&block)
|
41
62
|
end
|
42
63
|
|
43
64
|
#
|
44
65
|
# Defines the `dm:doc:graphviz` namespace.
|
45
66
|
#
|
46
67
|
def define
|
68
|
+
graphviz = lambda { |type,format|
|
69
|
+
GraphViz.new(@options.merge(
|
70
|
+
:naming => type,
|
71
|
+
:file => "doc/#{type}_diagram",
|
72
|
+
:format => format
|
73
|
+
))
|
74
|
+
}
|
75
|
+
|
47
76
|
super do
|
48
|
-
namespace
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
77
|
+
namespace(:graphviz) do
|
78
|
+
@diagrams.each do |type|
|
79
|
+
namespace(type) do
|
80
|
+
@formats.each do |format|
|
81
|
+
desc "Generates a #{format.to_s.upcase} GraphViz #{type} diagram of the DataMapper Models"
|
82
|
+
task(format) do
|
83
|
+
graphviz[type, format].visualize!
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
53
87
|
|
54
|
-
|
55
|
-
task :schema do
|
56
|
-
@schema.visualize!
|
88
|
+
task(type => @formats.map { |format| "#{type}:#{format}" })
|
57
89
|
end
|
58
90
|
end
|
59
91
|
|
60
|
-
task
|
92
|
+
task(:graphviz => @diagrams.map { |type| "graphviz:#{type}" })
|
61
93
|
end
|
62
94
|
end
|
63
95
|
|
@@ -3,9 +3,16 @@ module DataMapper
|
|
3
3
|
module Rake
|
4
4
|
module Rails
|
5
5
|
module Tasks
|
6
|
+
#
|
7
|
+
# Disables Bundler by default.
|
8
|
+
#
|
9
|
+
def initialize(options={},&block)
|
10
|
+
super({:bundle => false}.merge(options),&block)
|
11
|
+
end
|
12
|
+
|
6
13
|
#
|
7
14
|
# Overrides the Rake `task` method to make sure every defined
|
8
|
-
# task depends on `
|
15
|
+
# task depends on `environment`.
|
9
16
|
#
|
10
17
|
# @param [Array] arguments
|
11
18
|
# The arguments of the task.
|
@@ -14,7 +21,7 @@ module DataMapper
|
|
14
21
|
if arguments.first.kind_of?(Hash)
|
15
22
|
super(*arguments)
|
16
23
|
else
|
17
|
-
super(arguments.first =>
|
24
|
+
super(arguments.first => :environment)
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
@@ -4,9 +4,16 @@ module DataMapper
|
|
4
4
|
module Visualizer
|
5
5
|
module Rake
|
6
6
|
class Task < ::Rake::TaskLib
|
7
|
+
|
8
|
+
# Options for the DataMapper Visualizer.
|
9
|
+
attr_reader :options
|
10
|
+
|
7
11
|
#
|
8
12
|
# Creates a new task.
|
9
13
|
#
|
14
|
+
# @param [Hash] options
|
15
|
+
# Options for the DataMapper Visualizer.
|
16
|
+
#
|
10
17
|
# @yield [task]
|
11
18
|
# The given block will be passed the newly created task.
|
12
19
|
#
|
@@ -14,6 +21,11 @@ module DataMapper
|
|
14
21
|
# The new Task.
|
15
22
|
#
|
16
23
|
def initialize(options={})
|
24
|
+
@options = {
|
25
|
+
:bundle => File.file?('Gemfile')
|
26
|
+
}
|
27
|
+
@options.merge!(options)
|
28
|
+
|
17
29
|
yield self if block_given?
|
18
30
|
|
19
31
|
define()
|
@@ -9,13 +9,6 @@ module DataMapper
|
|
9
9
|
#
|
10
10
|
class Visualization
|
11
11
|
|
12
|
-
# The inflector to use
|
13
|
-
Inflector = if Object.const_defined?('ActiveSupport')
|
14
|
-
ActiveSupport::Inflector
|
15
|
-
else
|
16
|
-
Extlib::Inflection
|
17
|
-
end
|
18
|
-
|
19
12
|
# The project that will be visualized
|
20
13
|
attr_reader :project
|
21
14
|
|
@@ -90,7 +83,7 @@ module DataMapper
|
|
90
83
|
obj.class.name
|
91
84
|
end
|
92
85
|
|
93
|
-
name = Inflector.demodulize(name) unless @full_names
|
86
|
+
name = DataMapper::Inflector.demodulize(name) unless @full_names
|
94
87
|
|
95
88
|
return name
|
96
89
|
end
|
@@ -134,7 +127,7 @@ module DataMapper
|
|
134
127
|
# The property type name.
|
135
128
|
#
|
136
129
|
def property_type_name(property)
|
137
|
-
class_name(property.
|
130
|
+
class_name(property.class)
|
138
131
|
end
|
139
132
|
|
140
133
|
#
|
data/spec/dm_visualizer_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/visualization_spec.rb
CHANGED
@@ -6,10 +6,6 @@ require 'helpers/project'
|
|
6
6
|
describe DataMapper::Visualizer::Visualization do
|
7
7
|
include Helpers::Project
|
8
8
|
|
9
|
-
it "should detect which inflector DataMapper is using" do
|
10
|
-
DataMapper::Visualizer::Visualization::Inflector.should_not be_nil
|
11
|
-
end
|
12
|
-
|
13
9
|
describe "defaults" do
|
14
10
|
before(:all) do
|
15
11
|
@vis = DataMapper::Visualizer::Visualization.new(
|
@@ -23,7 +19,7 @@ describe DataMapper::Visualizer::Visualization do
|
|
23
19
|
end
|
24
20
|
|
25
21
|
it "should return the class names of Objects" do
|
26
|
-
@vis.class_name(Blog::Post.body).should == '
|
22
|
+
@vis.class_name(Blog::Post.body).should == 'Text'
|
27
23
|
end
|
28
24
|
|
29
25
|
it "should return the names of properties" do
|
@@ -78,11 +74,13 @@ describe DataMapper::Visualizer::Visualization do
|
|
78
74
|
end
|
79
75
|
|
80
76
|
it "should not demodulize the names of Objects" do
|
81
|
-
|
77
|
+
object = Blog::Post.new
|
78
|
+
|
79
|
+
@vis.class_name(object).should == 'Blog::Post'
|
82
80
|
end
|
83
81
|
|
84
82
|
it "should not demodulize property type names" do
|
85
|
-
@vis.property_type_name(Blog::Post.body).should
|
83
|
+
@vis.property_type_name(Blog::Post.body).should =~ /::Text$/
|
86
84
|
end
|
87
85
|
|
88
86
|
it "should not demodulize model names" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-visualizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Postmodern
|
@@ -15,89 +15,73 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-02-09 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
name: dm-core
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
28
|
+
hash: 23
|
30
29
|
segments:
|
30
|
+
- 1
|
31
31
|
- 0
|
32
|
-
-
|
33
|
-
|
34
|
-
|
32
|
+
- 0
|
33
|
+
version: 1.0.0
|
34
|
+
prerelease: false
|
35
35
|
type: :runtime
|
36
|
-
|
36
|
+
requirement: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
-
|
40
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
name: ruby-graphviz
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
40
|
none: false
|
42
41
|
requirements:
|
43
42
|
- - ">="
|
44
43
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
44
|
+
hash: 47
|
46
45
|
segments:
|
47
46
|
- 0
|
47
|
+
- 9
|
48
48
|
- 10
|
49
|
-
|
50
|
-
version: 0.10.2
|
51
|
-
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: thor
|
49
|
+
version: 0.9.10
|
55
50
|
prerelease: false
|
56
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
hash: 35
|
62
|
-
segments:
|
63
|
-
- 0
|
64
|
-
- 13
|
65
|
-
- 4
|
66
|
-
version: 0.13.4
|
67
51
|
type: :runtime
|
68
|
-
|
52
|
+
requirement: *id002
|
69
53
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
|
72
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
54
|
+
name: yard
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
73
56
|
none: false
|
74
57
|
requirements:
|
75
58
|
- - ~>
|
76
59
|
- !ruby/object:Gem::Version
|
77
|
-
hash:
|
60
|
+
hash: 7
|
78
61
|
segments:
|
79
|
-
- 1
|
80
|
-
- 3
|
81
62
|
- 0
|
82
|
-
|
63
|
+
- 6
|
64
|
+
- 0
|
65
|
+
version: 0.6.0
|
66
|
+
prerelease: false
|
83
67
|
type: :development
|
84
|
-
|
68
|
+
requirement: *id003
|
85
69
|
- !ruby/object:Gem::Dependency
|
86
|
-
name:
|
87
|
-
|
88
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
70
|
+
name: bundler
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
89
72
|
none: false
|
90
73
|
requirements:
|
91
74
|
- - ~>
|
92
75
|
- !ruby/object:Gem::Version
|
93
|
-
hash:
|
76
|
+
hash: 23
|
94
77
|
segments:
|
78
|
+
- 1
|
95
79
|
- 0
|
96
|
-
-
|
97
|
-
|
98
|
-
|
80
|
+
- 0
|
81
|
+
version: 1.0.0
|
82
|
+
prerelease: false
|
99
83
|
type: :development
|
100
|
-
|
84
|
+
requirement: *id004
|
101
85
|
description: DataMapper Visualizer is both a library and a command-line utility for visualizing the Models, Properties and Relationships defined in a DataMapper based Ruby project.
|
102
86
|
email: postmodern.mod3@gmail.com
|
103
87
|
executables: []
|
@@ -105,47 +89,45 @@ executables: []
|
|
105
89
|
extensions: []
|
106
90
|
|
107
91
|
extra_rdoc_files:
|
108
|
-
- ChangeLog.md
|
109
|
-
- LICENSE.txt
|
110
92
|
- README.md
|
111
93
|
files:
|
112
|
-
- .
|
113
|
-
- .
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
- spec/project_examples.rb
|
96
|
+
- gemspec.yml
|
97
|
+
- .rspec
|
98
|
+
- spec/helpers/projects/rails/app/models/user.rb
|
99
|
+
- lib/dm-visualizer/rake/task.rb
|
114
100
|
- .yardopts
|
115
|
-
-
|
116
|
-
-
|
117
|
-
-
|
118
|
-
-
|
119
|
-
- VERSION
|
120
|
-
- dm-visualizer.gemspec
|
121
|
-
- lib/dm-visualizer.rb
|
101
|
+
- spec/visualization_spec.rb
|
102
|
+
- spec/project_spec.rb
|
103
|
+
- spec/helpers/projects/rails/app/models/post.rb
|
104
|
+
- spec/helpers/project.rb
|
122
105
|
- lib/dm-visualizer/graphviz.rb
|
123
|
-
- lib/dm-visualizer/project.rb
|
124
|
-
- lib/dm-visualizer/rake/graphviz_task.rb
|
125
|
-
- lib/dm-visualizer/rake/rails/graphviz_task.rb
|
126
|
-
- lib/dm-visualizer/rake/rails/tasks.rb
|
127
|
-
- lib/dm-visualizer/rake/task.rb
|
128
106
|
- lib/dm-visualizer/visualization.rb
|
129
|
-
-
|
130
|
-
-
|
131
|
-
- spec/helpers/projects/library/lib/blog.rb
|
107
|
+
- lib/dm-visualizer/rake/graphviz_task.rb
|
108
|
+
- Gemfile
|
132
109
|
- spec/helpers/projects/library/lib/blog/comment.rb
|
110
|
+
- Rakefile
|
111
|
+
- README.md
|
112
|
+
- LICENSE.txt
|
113
|
+
- spec/dm_visualizer_spec.rb
|
114
|
+
- lib/dm-visualizer/rake/rails/tasks.rb
|
115
|
+
- spec/helpers/projects/rails/app/models/comment.rb
|
133
116
|
- spec/helpers/projects/library/lib/blog/post.rb
|
117
|
+
- lib/dm-visualizer.rb
|
118
|
+
- dm-visualizer.gemspec
|
134
119
|
- spec/helpers/projects/library/lib/blog/user.rb
|
135
|
-
- spec/helpers/projects/
|
136
|
-
-
|
137
|
-
-
|
138
|
-
-
|
139
|
-
|
140
|
-
- spec/spec_helper.rb
|
141
|
-
- spec/visualization_spec.rb
|
142
|
-
has_rdoc: yard
|
120
|
+
- spec/helpers/projects/library/lib/blog.rb
|
121
|
+
- lib/dm-visualizer/rake/rails/graphviz_task.rb
|
122
|
+
- lib/dm-visualizer/project.rb
|
123
|
+
- ChangeLog.md
|
124
|
+
has_rdoc: true
|
143
125
|
homepage: http://github.com/postmodern/dm-visualizer
|
144
126
|
licenses:
|
145
127
|
- MIT
|
146
128
|
post_install_message:
|
147
|
-
rdoc_options:
|
148
|
-
|
129
|
+
rdoc_options: []
|
130
|
+
|
149
131
|
require_paths:
|
150
132
|
- lib
|
151
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -162,28 +144,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
144
|
requirements:
|
163
145
|
- - ">="
|
164
146
|
- !ruby/object:Gem::Version
|
165
|
-
hash:
|
147
|
+
hash: 23
|
166
148
|
segments:
|
167
|
-
-
|
168
|
-
|
149
|
+
- 1
|
150
|
+
- 3
|
151
|
+
- 6
|
152
|
+
version: 1.3.6
|
169
153
|
requirements: []
|
170
154
|
|
171
|
-
rubyforge_project:
|
172
|
-
rubygems_version: 1.
|
155
|
+
rubyforge_project: dm-visualizer
|
156
|
+
rubygems_version: 1.5.0
|
173
157
|
signing_key:
|
174
158
|
specification_version: 3
|
175
159
|
summary: Visualizes the Models, Properties and Relationships defined in a DataMapper based Ruby project.
|
176
160
|
test_files:
|
177
161
|
- spec/project_spec.rb
|
178
|
-
- spec/spec_helper.rb
|
179
|
-
- spec/visualization_spec.rb
|
180
|
-
- spec/project_examples.rb
|
181
|
-
- spec/helpers/project.rb
|
182
|
-
- spec/helpers/projects/library/lib/blog.rb
|
183
|
-
- spec/helpers/projects/library/lib/blog/post.rb
|
184
|
-
- spec/helpers/projects/library/lib/blog/user.rb
|
185
|
-
- spec/helpers/projects/library/lib/blog/comment.rb
|
186
|
-
- spec/helpers/projects/rails/app/models/post.rb
|
187
|
-
- spec/helpers/projects/rails/app/models/user.rb
|
188
|
-
- spec/helpers/projects/rails/app/models/comment.rb
|
189
162
|
- spec/dm_visualizer_spec.rb
|
163
|
+
- spec/visualization_spec.rb
|
data/.gitignore
DELETED
data/.specopts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour --format specdoc
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.0
|