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
ace6cdd7
Commit
ace6cdd7
authored
Jun 29, 2011
by
Robert Wahler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove trailing whitespace
Because my editor is set to do whitespace cleanup on write
parent
7c5965a5
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
40 additions
and
40 deletions
+40
-40
History.txt
History.txt
+1
-1
README.rdoc
README.rdoc
+2
-2
Rakefile
Rakefile
+3
-3
annotate
bin/annotate
+10
-10
annotate.rb
lib/annotate.rb
+1
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+11
-11
annotate_routes.rb
lib/annotate/annotate_routes.rb
+11
-11
migrate.rake
tasks/migrate.rake
+1
-1
No files found.
History.txt
View file @
ace6cdd7
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
* -i to show database indexes in annotations
* -i to show database indexes in annotations
* -e to exclude annotating tests or fixtures
* -e to exclude annotating tests or fixtures
* -m to include the migration version number in the annotation
* -m to include the migration version number in the annotation
* --model-dir to annotate model files stored a different place than app/models
* --model-dir to annotate model files stored a different place than app/models
* Ignore unknown macros ('acts_as_whatever')
* Ignore unknown macros ('acts_as_whatever')
== 2.0 2009-02-03
== 2.0 2009-02-03
...
...
README.rdoc
View file @
ace6cdd7
...
@@ -70,7 +70,7 @@ To annotate routes.rb:
...
@@ -70,7 +70,7 @@ To annotate routes.rb:
annotate -r
annotate -r
To automatically annotate after running 'rake db:migrate':
To automatically annotate after running 'rake db:migrate':
[needs more clarity] unpack the gem into vendor/plugins, or maybe vendor/gems, or maybe just require tasks/migrate.rake.
[needs more clarity] unpack the gem into vendor/plugins, or maybe vendor/gems, or maybe just require tasks/migrate.rake.
If you install annotate_models as a plugin, it will automatically
If you install annotate_models as a plugin, it will automatically
...
@@ -137,5 +137,5 @@ Modifications by:
...
@@ -137,5 +137,5 @@ Modifications by:
- Gavin Montague - http://github.com/govan/
- Gavin Montague - http://github.com/govan/
- Alexander Semyonov - http://github.com/rotuka/
- Alexander Semyonov - http://github.com/rotuka/
- Nathan Brazil - http://github.com/bitaxis/
- Nathan Brazil - http://github.com/bitaxis/
and many others that I may have missed to add.
and many others that I may have missed to add.
Rakefile
View file @
ace6cdd7
...
@@ -17,15 +17,15 @@ begin
...
@@ -17,15 +17,15 @@ begin
gem
.
authors
=
[
'Cuong Tran'
,
"Alex Chaffee"
,
"Marcos Piccinini"
]
gem
.
authors
=
[
'Cuong Tran'
,
"Alex Chaffee"
,
"Marcos Piccinini"
]
gem
.
files
=
FileList
[
"[A-Z]*.*"
,
"{bin,lib,tasks,spec}/**/*"
]
gem
.
files
=
FileList
[
"[A-Z]*.*"
,
"{bin,lib,tasks,spec}/**/*"
]
gem
.
rubyforge_project
=
"annotate"
gem
.
rubyforge_project
=
"annotate"
# note that Jeweler automatically reads the version from VERSION.yml
# note that Jeweler automatically reads the version from VERSION.yml
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
end
Jeweler
::
RubyforgeTasks
.
new
do
|
rubyforge
|
Jeweler
::
RubyforgeTasks
.
new
do
|
rubyforge
|
rubyforge
.
doc_task
=
"rdoc"
rubyforge
.
doc_task
=
"rdoc"
end
end
rescue
LoadError
rescue
LoadError
puts
"Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
puts
"Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
end
...
...
bin/annotate
View file @
ace6cdd7
...
@@ -8,33 +8,33 @@ task = :annotate_models
...
@@ -8,33 +8,33 @@ task = :annotate_models
OptionParser
.
new
do
|
opts
|
OptionParser
.
new
do
|
opts
|
opts
.
banner
=
"Usage: annotate [options] [model_file]*"
opts
.
banner
=
"Usage: annotate [options] [model_file]*"
opts
.
on
(
'-d'
,
'--delete'
,
opts
.
on
(
'-d'
,
'--delete'
,
"Remove annotations from all model files"
)
do
"Remove annotations from all model files"
)
do
task
=
:remove_annotation
task
=
:remove_annotation
end
end
opts
.
on
(
'-p'
,
'--position [before|after]'
,
[
'before'
,
'after'
],
opts
.
on
(
'-p'
,
'--position [before|after]'
,
[
'before'
,
'after'
],
"Place the annotations at the top (before) or the bottom (after) of the model file"
)
do
|
p
|
"Place the annotations at the top (before) or the bottom (after) of the model file"
)
do
|
p
|
ENV
[
'position'
]
=
p
ENV
[
'position'
]
=
p
end
end
opts
.
on
(
'-r'
,
'--routes'
,
opts
.
on
(
'-r'
,
'--routes'
,
"Annotate routes.rb with the output of 'rake routes'"
)
do
"Annotate routes.rb with the output of 'rake routes'"
)
do
task
=
:annotate_routes
task
=
:annotate_routes
end
end
opts
.
on
(
'-v'
,
'--version'
,
opts
.
on
(
'-v'
,
'--version'
,
"Show the current version of this gem"
)
do
"Show the current version of this gem"
)
do
puts
"annotate v
#{
Annotate
.
version
}
"
;
exit
puts
"annotate v
#{
Annotate
.
version
}
"
;
exit
end
end
opts
.
on
(
'-m'
,
'--show-migration'
,
opts
.
on
(
'-m'
,
'--show-migration'
,
"Include the migration version number in the annotation"
)
do
"Include the migration version number in the annotation"
)
do
ENV
[
'include_version'
]
=
"yes"
ENV
[
'include_version'
]
=
"yes"
end
end
opts
.
on
(
'-i'
,
'--show-indexes'
,
opts
.
on
(
'-i'
,
'--show-indexes'
,
"List the table's database indexes in the annotation"
)
do
"List the table's database indexes in the annotation"
)
do
ENV
[
'show_indexes'
]
=
"yes"
ENV
[
'show_indexes'
]
=
"yes"
end
end
...
@@ -43,7 +43,7 @@ OptionParser.new do |opts|
...
@@ -43,7 +43,7 @@ OptionParser.new do |opts|
ENV
[
'simple_indexes'
]
=
"yes"
ENV
[
'simple_indexes'
]
=
"yes"
end
end
opts
.
on
(
'--model-dir dir'
,
opts
.
on
(
'--model-dir dir'
,
"Annotate model files stored in dir rather than app/models"
)
do
|
dir
|
"Annotate model files stored in dir rather than app/models"
)
do
|
dir
|
ENV
[
'model_dir'
]
=
dir
ENV
[
'model_dir'
]
=
dir
end
end
...
...
lib/annotate.rb
View file @
ace6cdd7
...
@@ -13,7 +13,7 @@ module Annotate
...
@@ -13,7 +13,7 @@ module Annotate
version
=
"0.0.0"
version
=
"0.0.0"
end
end
end
end
def
self
.
load_tasks
def
self
.
load_tasks
if
File
.
exists?
(
'Rakefile'
)
if
File
.
exists?
(
'Rakefile'
)
require
'rake'
require
'rake'
...
...
lib/annotate/annotate_models.rb
View file @
ace6cdd7
...
@@ -178,12 +178,12 @@ module AnnotateModels
...
@@ -178,12 +178,12 @@ module AnnotateModels
if
annotate_one_file
(
model_file_name
,
info
,
options_with_position
(
options
,
:position_in_class
))
if
annotate_one_file
(
model_file_name
,
info
,
options_with_position
(
options
,
:position_in_class
))
annotated
=
true
annotated
=
true
end
end
unless
ENV
[
'exclude_tests'
]
unless
ENV
[
'exclude_tests'
]
[
[
File
.
join
(
UNIT_TEST_DIR
,
"
#{
model_name
}
_test.rb"
),
# test
File
.
join
(
UNIT_TEST_DIR
,
"
#{
model_name
}
_test.rb"
),
# test
File
.
join
(
SPEC_MODEL_DIR
,
"
#{
model_name
}
_spec.rb"
),
# spec
File
.
join
(
SPEC_MODEL_DIR
,
"
#{
model_name
}
_spec.rb"
),
# spec
].
each
do
|
file
|
].
each
do
|
file
|
# todo: add an option "position_in_test" -- or maybe just ask if anyone ever wants different positions for model vs. test vs. fixture
# todo: add an option "position_in_test" -- or maybe just ask if anyone ever wants different positions for model vs. test vs. fixture
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
end
end
...
@@ -194,14 +194,14 @@ module AnnotateModels
...
@@ -194,14 +194,14 @@ module AnnotateModels
File
.
join
(
EXEMPLARS_TEST_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
EXEMPLARS_TEST_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
EXEMPLARS_SPEC_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
EXEMPLARS_SPEC_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
BLUEPRINTS_DIR
,
"
#{
model_name
}
_blueprint.rb"
),
# Machinist Blueprints
File
.
join
(
BLUEPRINTS_DIR
,
"
#{
model_name
}
_blueprint.rb"
),
# Machinist Blueprints
].
each
do
|
file
|
].
each
do
|
file
|
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
end
end
FIXTURE_DIRS
.
each
do
|
dir
|
FIXTURE_DIRS
.
each
do
|
dir
|
fixture_file_name
=
File
.
join
(
dir
,
klass
.
table_name
+
".yml"
)
fixture_file_name
=
File
.
join
(
dir
,
klass
.
table_name
+
".yml"
)
if
File
.
exist?
(
fixture_file_name
)
if
File
.
exist?
(
fixture_file_name
)
annotate_one_file
(
fixture_file_name
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
annotate_one_file
(
fixture_file_name
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
end
end
end
end
end
end
...
@@ -210,14 +210,14 @@ module AnnotateModels
...
@@ -210,14 +210,14 @@ module AnnotateModels
[
[
File
.
join
(
SPEC_FACTORIES_DIR
,
"
#{
model_name
}
_factory.rb"
),
# spec/factories
File
.
join
(
SPEC_FACTORIES_DIR
,
"
#{
model_name
}
_factory.rb"
),
# spec/factories
File
.
join
(
TEST_FACTORIES_DIR
,
"
#{
model_name
}
_factory.rb"
),
# test/factories
File
.
join
(
TEST_FACTORIES_DIR
,
"
#{
model_name
}
_factory.rb"
),
# test/factories
].
each
do
|
file
|
].
each
do
|
file
|
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_factory
))
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_factory
))
end
end
end
end
annotated
annotated
end
end
# position = :position_in_fixture or :position_in_class
# position = :position_in_fixture or :position_in_class
def
options_with_position
(
options
,
position_in
)
def
options_with_position
(
options
,
position_in
)
options
.
merge
(
:position
=>
(
options
[
position_in
]
||
options
[
:position
]))
options
.
merge
(
:position
=>
(
options
[
position_in
]
||
options
[
:position
]))
...
@@ -298,7 +298,7 @@ module AnnotateModels
...
@@ -298,7 +298,7 @@ module AnnotateModels
puts
"Unable to annotate
#{
file
}
:
#{
e
.
inspect
}
"
puts
"Unable to annotate
#{
file
}
:
#{
e
.
inspect
}
"
puts
""
puts
""
# todo: check if all backtrace lines are in "gems" -- if so, it's an annotate bug, so print the whole stack trace.
# todo: check if all backtrace lines are in "gems" -- if so, it's an annotate bug, so print the whole stack trace.
# puts e.backtrace.join("\n\t")
# puts e.backtrace.join("\n\t")
end
end
end
end
if
annotated
.
empty?
if
annotated
.
empty?
...
@@ -327,17 +327,17 @@ module AnnotateModels
...
@@ -327,17 +327,17 @@ module AnnotateModels
fixture_file_name
=
File
.
join
(
dir
,
klass
.
table_name
+
".yml"
)
fixture_file_name
=
File
.
join
(
dir
,
klass
.
table_name
+
".yml"
)
remove_annotation_of_file
(
fixture_file_name
)
if
File
.
exist?
(
fixture_file_name
)
remove_annotation_of_file
(
fixture_file_name
)
if
File
.
exist?
(
fixture_file_name
)
end
end
[
File
.
join
(
UNIT_TEST_DIR
,
"
#{
klass
.
name
.
underscore
}
_test.rb"
),
[
File
.
join
(
UNIT_TEST_DIR
,
"
#{
klass
.
name
.
underscore
}
_test.rb"
),
File
.
join
(
SPEC_MODEL_DIR
,
"
#{
klass
.
name
.
underscore
}
_spec.rb"
)].
each
do
|
file
|
File
.
join
(
SPEC_MODEL_DIR
,
"
#{
klass
.
name
.
underscore
}
_spec.rb"
)].
each
do
|
file
|
remove_annotation_of_file
(
file
)
if
File
.
exist?
(
file
)
remove_annotation_of_file
(
file
)
if
File
.
exist?
(
file
)
end
end
[
File
.
join
(
SPEC_FACTORIES_DIR
,
"
#{
klass
.
name
.
underscore
}
_factory.rb"
),
[
File
.
join
(
SPEC_FACTORIES_DIR
,
"
#{
klass
.
name
.
underscore
}
_factory.rb"
),
File
.
join
(
TEST_FACTORIES_DIR
,
"
#{
klass
.
name
.
underscore
}
_factory.rb"
)].
each
do
|
file
|
File
.
join
(
TEST_FACTORIES_DIR
,
"
#{
klass
.
name
.
underscore
}
_factory.rb"
)].
each
do
|
file
|
remove_annotation_of_file
(
file
)
if
File
.
exist?
(
file
)
remove_annotation_of_file
(
file
)
if
File
.
exist?
(
file
)
end
end
end
end
rescue
Exception
=>
e
rescue
Exception
=>
e
puts
"Unable to annotate
#{
file
}
:
#{
e
.
message
}
"
puts
"Unable to annotate
#{
file
}
:
#{
e
.
message
}
"
...
...
lib/annotate/annotate_routes.rb
View file @
ace6cdd7
# == Annotate Routes
# == Annotate Routes
#
#
# Based on:
# Based on:
#
#
#
#
#
#
# Prepends the output of "rake routes" to the top of your routes.rb file.
# Prepends the output of "rake routes" to the top of your routes.rb file.
# Yes, it's simple but I'm thick and often need a reminder of what my routes mean.
# Yes, it's simple but I'm thick and often need a reminder of what my routes mean.
#
#
# Running this task will replace any exising route comment generated by the task.
# Running this task will replace any exising route comment generated by the task.
# Best to back up your routes file before running:
# Best to back up your routes file before running:
#
#
# Author:
# Author:
# Gavin Montague
# Gavin Montague
# gavin@leftbrained.co.uk
# gavin@leftbrained.co.uk
#
#
# Released under the same license as Ruby. No Support. No Warranty.module AnnotateRoutes
# Released under the same license as Ruby. No Support. No Warranty.module AnnotateRoutes
#
#
module
AnnotateRoutes
module
AnnotateRoutes
PREFIX
=
"#== Route Map"
PREFIX
=
"#== Route Map"
def
self
.
do_annotate
def
self
.
do_annotate
routes_rb
=
File
.
join
(
"config"
,
"routes.rb"
)
routes_rb
=
File
.
join
(
"config"
,
"routes.rb"
)
header
=
PREFIX
+
"
\n
# Generated on
#{
Time
.
now
.
strftime
(
"%d %b %Y %H:%M"
)
}
\n
#"
header
=
PREFIX
+
"
\n
# Generated on
#{
Time
.
now
.
strftime
(
"%d %b %Y %H:%M"
)
}
\n
#"
if
File
.
exists?
routes_rb
if
File
.
exists?
routes_rb
...
@@ -29,8 +29,8 @@ module AnnotateRoutes
...
@@ -29,8 +29,8 @@ module AnnotateRoutes
routes_map
=
routes_map
.
inject
(
header
){
|
sum
,
line
|
sum
<<
"
\n
# "
<<
line
}
routes_map
=
routes_map
.
inject
(
header
){
|
sum
,
line
|
sum
<<
"
\n
# "
<<
line
}
content = File.read(routes_rb)
content = File.read(routes_rb)
content, old = content.split(/^#== Route .*?
\n
/)
content, old = content.split(/^#== Route .*?
\n
/)
File.open(routes_rb, "wb") do |f|
File.open(routes_rb, "wb") do |f|
f.puts content.sub!(/
\n
?
\z
/, "
\n
") + routes_map
f.puts content.sub!(/
\n
?
\z
/, "
\n
") + routes_map
end
end
puts "Route file annotated."
puts "Route file annotated."
else
else
...
...
tasks/migrate.rake
View file @
ace6cdd7
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
# (They are not used to build annotate itself.)
# (They are not used to build annotate itself.)
# Append annotations to Rake tasks for ActiveRecord, so annotate automatically gets
# Append annotations to Rake tasks for ActiveRecord, so annotate automatically gets
# run after doing db:migrate.
# run after doing db:migrate.
# Unfortunately it relies on ENV for options; it'd be nice to be able to set options
# Unfortunately it relies on ENV for options; it'd be nice to be able to set options
# in a per-project config file so this task can read them.
# in a per-project config file so this task can read them.
namespace
:db
do
namespace
:db
do
...
...
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