Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
annotate
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
annotate
Commits
e51c3418
Commit
e51c3418
authored
14 years ago
by
Phil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
render Schema Information as RDoc
parent
9c68c8c9
develop
…
v3.2.0
v3.1.1
v3.1.1-release
v3.1.0
v3.0.3
v3.0.2
v3.0.0
v2.7.5
v2.7.4
v2.7.3
v2.7.2
v2.7.1
v2.7.0
v2.6.10
v2.6.9
v2.6.8
v2.6.7
v2.6.6
v2.6.5
v2.6.4
v2.6.3
v2.6.2
v2.6.0
v2.5.0
release/v3.0.1
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
29 deletions
+51
-29
README.rdoc
README.rdoc
+9
-0
Rakefile
Rakefile
+10
-10
VERSION.yml
VERSION.yml
+2
-2
annotate.gemspec
annotate.gemspec
+10
-8
annotate.rb
lib/annotate.rb
+2
-0
annotate_models.rb
lib/annotate/annotate_models.rb
+18
-9
No files found.
README.rdoc
View file @
e51c3418
This is a crude hacked version of Annotate, which accomplishes one
task: I renders the Schema Information as RDoc Format, so that a
subsequent `rake doc:app` will include the Schema Information in the
generated documentation.
This version is incompatible with previous Versions of Annotate and
doesn't not come with any helpers to bridge that gap.
== Annotate (aka AnnotateModels)
Add a comment summarizing the current schema to the top or bottom of each of your...
...
...
This diff is collapsed.
Click to expand it.
Rakefile
View file @
e51c3418
...
...
@@ -30,17 +30,17 @@ rescue LoadError
puts
"Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
require
'spec/rake/spectask'
Spec
::
Rake
::
SpecTask
.
new
(
:spec
)
do
|
spec
|
spec
.
libs
<<
'lib'
<<
'spec'
spec
.
spec_files
=
FileList
[
'spec/**/*_spec.rb'
]
end
#
require 'spec/rake/spectask'
#
Spec::Rake::SpecTask.new(:spec) do |spec|
#
spec.libs << 'lib' << 'spec'
#
spec.spec_files = FileList['spec/**/*_spec.rb']
#
end
Spec
::
Rake
::
SpecTask
.
new
(
:rcov
)
do
|
spec
|
spec
.
libs
<<
'lib'
<<
'spec'
spec
.
pattern
=
'spec/**/*_spec.rb'
spec
.
rcov
=
true
end
#
Spec::Rake::SpecTask.new(:rcov) do |spec|
#
spec.libs << 'lib' << 'spec'
#
spec.pattern = 'spec/**/*_spec.rb'
#
spec.rcov = true
#
end
require
'rake/rdoctask'
Rake
::
RDocTask
.
new
do
|
rdoc
|
...
...
This diff is collapsed.
Click to expand it.
VERSION.yml
View file @
e51c3418
---
:major
:
2
:minor
:
4
:major
:
3
:minor
:
0
:patch
:
0
This diff is collapsed.
Click to expand it.
annotate.gemspec
View file @
e51c3418
# Generated by jeweler
# DO NOT EDIT THIS FILE
# Instead, edit Jeweler::Tasks in Rakefile, and run
`rake gemspec`
# DO NOT EDIT THIS FILE
DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run
the gemspec command
# -*- encoding: utf-8 -*-
Gem
::
Specification
.
new
do
|
s
|
s
.
name
=
%q{annotate}
s
.
version
=
"
2.4
.0"
s
.
version
=
"
3.0
.0"
s
.
required_rubygems_version
=
Gem
::
Requirement
.
new
(
">= 0"
)
if
s
.
respond_to?
:required_rubygems_version
=
s
.
authors
=
[
"Cuong Tran"
,
"Alex Chaffee"
,
"Marcos Piccinini"
]
s
.
date
=
%q{20
09-10-23
}
s
.
date
=
%q{20
10-06-17
}
s
.
default_executable
=
%q{annotate}
s
.
description
=
%q{Annotates Rails Models, routes, fixtures, and others based on the database schema.}
s
.
email
=
[
"alex@stinky.com"
,
"ctran@pragmaquest.com"
,
"x@nofxx.com"
]
...
...
@@ -37,13 +37,14 @@ Gem::Specification.new do |s|
s
.
homepage
=
%q{http://github.com/ctran/annotate}
s
.
rdoc_options
=
[
"--charset=UTF-8"
]
s
.
require_paths
=
[
"lib"
]
s
.
rubygems_version
=
%q{1.3.5}
s
.
rubyforge_project
=
%q{annotate}
s
.
rubygems_version
=
%q{1.3.6}
s
.
summary
=
%q{Annotates Rails Models, routes, fixtures, and others based on the database schema.}
s
.
test_files
=
[
"spec/annotate/annotate_models_spec.rb"
,
"spec/spec_helper.rb"
,
"spec/annotate/annotate_models_spec.rb"
,
"spec/annotate/annotate_routes_spec.rb"
,
"spec/annotate_spec.rb"
,
"spec/spec_helper.rb"
"spec/annotate_spec.rb"
]
if
s
.
respond_to?
:specification_version
then
...
...
@@ -56,3 +57,4 @@ Gem::Specification.new do |s|
else
end
end
This diff is collapsed.
Click to expand it.
lib/annotate.rb
View file @
e51c3418
$:
.
unshift
(
File
.
dirname
(
__FILE__
))
unless
$:
.
include?
(
File
.
dirname
(
__FILE__
))
||
$:
.
include?
(
File
.
expand_path
(
File
.
dirname
(
__FILE__
)))
require
'yaml'
module
Annotate
def
self
.
version
version_file
=
File
.
dirname
(
__FILE__
)
+
"/../VERSION.yml"
...
...
This diff is collapsed.
Click to expand it.
lib/annotate/annotate_models.rb
View file @
e51c3418
module
AnnotateModels
class
<<
self
# Annotate Models plugin use this header
COMPAT_PREFIX
=
"== Schema Info"
PREFIX
=
"== Schema Information"
END_MARK
=
"== Schema Information End"
PATTERN
=
/^#
#{
PREFIX
}
\n(#.*\n)*#--\n#
#{
END_MARK
}
\n#\+\+\n/
FIXTURE_DIRS
=
[
"test/fixtures"
,
"spec/fixtures"
]
# File.join for windows reverse bar compat?
...
...
@@ -42,10 +44,10 @@ module AnnotateModels
# each column. The line contains the column name,
# the type (and length), and any optional attributes
def
get_schema_info
(
klass
,
header
,
options
=
{})
info
=
"#
#{
header
}
\n
#
\n
"
info
<<
"#
Table name:
#{
klass
.
table_name
}
\n
#
\n
"
info
=
"#
#{
header
}
\n
#
\n
"
info
<<
"#Table name:
#{
klass
.
table_name
}
\n
#
\n
"
max_size
=
klass
.
column_names
.
collect
{
|
name
|
name
.
size
}.
max
+
1
max_size
=
klass
.
column_names
.
collect
{
|
name
|
name
.
size
}.
max
+
5
klass
.
columns
.
each
do
|
col
|
attrs
=
[]
attrs
<<
"default(
#{
quote
(
col
.
default
)
}
)"
unless
col
.
default
.
nil?
...
...
@@ -77,14 +79,17 @@ module AnnotateModels
end
end
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s:%-15.15s %s"
,
col
.
name
,
col_type
,
attrs
.
join
(
", "
)).
rstrip
+
"
\n
"
a
=
([
col_type
]
+
attrs
).
join
(
", "
)
line
=
sprintf
(
"#%-
#{
max_size
}
.
#{
max_size
}
s<tt>%s</tt>"
,
"*
#{
col
.
name
}
*::"
,
a
).
rstrip
+
"
\n
"
# puts line
info
<<
line
end
if
options
[
:show_indexes
]
info
<<
get_index_info
(
klass
)
end
info
<<
"#
\n
\n
"
info
<<
"#
--
\n
#== Schema Information End
\n
#++
\n
"
end
def
get_index_info
(
klass
)
...
...
@@ -119,15 +124,18 @@ module AnnotateModels
old_content
=
File
.
read
(
file_name
)
# Ignore the Schema version line because it changes with each migration
header
=
Regexp
.
new
(
/(^#
Table name:.*?\n(#.*\n)*\n
)/
)
header
=
Regexp
.
new
(
/(^#
Table name:.*?\n(#.*\n)*
)/
)
old_header
=
old_content
.
match
(
header
).
to_s
new_header
=
info_block
.
match
(
header
).
to_s
# puts "old_header: #{old_header}"
# puts "new_header: #{new_header}"
if
old_header
==
new_header
false
else
# Remove old schema info
old_content
.
sub!
(
/^#
#{
COMPAT_PREFIX
}
.*?\n(#.*\n)*\n/
,
''
)
old_content
.
sub!
(
PATTERN
,
''
)
# Write it back
new_content
=
options
[
:position
]
==
'before'
?
(
info_block
+
old_content
)
:
(
old_content
+
"
\n
"
+
info_block
)
...
...
@@ -142,7 +150,7 @@ module AnnotateModels
if
File
.
exist?
(
file_name
)
content
=
File
.
read
(
file_name
)
content
.
sub!
(
/^#
#{
COMPAT_PREFIX
}
.*?\n(#.*\n)*\n/
,
''
)
content
.
sub!
(
PATTERN
,
''
)
File
.
open
(
file_name
,
"wb"
)
{
|
f
|
f
.
puts
content
}
end
...
...
@@ -263,6 +271,7 @@ module AnnotateModels
annotated
=
[]
get_model_files
.
each
do
|
file
|
# puts "---------------- file: #{file}"
begin
klass
=
get_model_class
(
file
)
if
klass
<
ActiveRecord
::
Base
&&
!
klass
.
abstract_class?
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment