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
3fdb185d
Commit
3fdb185d
authored
Oct 15, 2010
by
miyucy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reindent (use ruby-mode.el)
parent
7d8f70f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
36 deletions
+36
-36
annotate
bin/annotate
+17
-17
annotate_models.rb
lib/annotate/annotate_models.rb
+19
-19
No files found.
bin/annotate
View file @
3fdb185d
...
...
@@ -8,48 +8,48 @@ task = :annotate_models
OptionParser
.
new
do
|
opts
|
opts
.
banner
=
"Usage: annotate [options] [model_file]*"
opts
.
on
(
'-d'
,
'--delete'
,
"Remove annotations from all model files"
)
do
opts
.
on
(
'-d'
,
'--delete'
,
"Remove annotations from all model files"
)
do
task
=
:remove_annotation
end
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
|
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
|
ENV
[
'position'
]
=
p
end
opts
.
on
(
'-r'
,
'--routes'
,
"Annotate routes.rb with the output of 'rake routes'"
)
do
opts
.
on
(
'-r'
,
'--routes'
,
"Annotate routes.rb with the output of 'rake routes'"
)
do
task
=
:annotate_routes
end
opts
.
on
(
'-v'
,
'--version'
,
"Show the current version of this gem"
)
do
opts
.
on
(
'-v'
,
'--version'
,
"Show the current version of this gem"
)
do
puts
"annotate v
#{
Annotate
.
version
}
"
;
exit
end
opts
.
on
(
'-m'
,
'--show-migration'
,
"Include the migration version number in the annotation"
)
do
opts
.
on
(
'-m'
,
'--show-migration'
,
"Include the migration version number in the annotation"
)
do
ENV
[
'include_version'
]
=
"yes"
end
opts
.
on
(
'-i'
,
'--show-indexes'
,
"List the table's database indexes in the annotation"
)
do
opts
.
on
(
'-i'
,
'--show-indexes'
,
"List the table's database indexes in the annotation"
)
do
ENV
[
'show_indexes'
]
=
"yes"
end
opts
.
on
(
'-s'
,
'--simple-indexes'
,
"Concat the column's related indexes in the annotation"
)
do
"Concat the column's related indexes in the annotation"
)
do
ENV
[
'simple_indexes'
]
=
"yes"
end
opts
.
on
(
'--model-dir dir'
,
"Annotate model files stored in dir rather than app/models"
)
do
|
dir
|
opts
.
on
(
'--model-dir dir'
,
"Annotate model files stored in dir rather than app/models"
)
do
|
dir
|
ENV
[
'model_dir'
]
=
dir
end
opts
.
on
(
'-R'
,
'--require path'
,
"Additional files to require before loading models"
)
do
|
path
|
"Additional files to require before loading models"
)
do
|
path
|
if
ENV
[
'require'
]
ENV
[
'require'
]
=
ENV
[
'require'
]
+
",
#{
path
}
"
else
...
...
@@ -57,7 +57,7 @@ OptionParser.new do |opts|
end
end
opts
.
on
(
'-e'
,
'--exclude [tests,fixtures
,factories]'
,
Array
,
"Do not annotate fixtures, test files, and/or factories
"
)
do
|
exclusions
|
opts
.
on
(
'-e'
,
'--exclude [tests,fixtures
]'
,
Array
,
"Do not annotate fixtures, test files, or both
"
)
do
|
exclusions
|
exclusions
.
each
{
|
exclusion
|
ENV
[
"exclude_
#{
exclusion
}
"
]
=
"yes"
}
end
...
...
lib/annotate/annotate_models.rb
View file @
3fdb185d
...
...
@@ -34,14 +34,14 @@ module AnnotateModels
# Simple quoting for the default column value
def
quote
(
value
)
case
value
when
NilClass
then
"NULL"
when
TrueClass
then
"TRUE"
when
FalseClass
then
"FALSE"
when
Float
,
Fixnum
,
Bignum
then
value
.
to_s
when
NilClass
then
"NULL"
when
TrueClass
then
"TRUE"
when
FalseClass
then
"FALSE"
when
Float
,
Fixnum
,
Bignum
then
value
.
to_s
# BigDecimals need to be output in a non-normalized form and quoted.
when
BigDecimal
then
value
.
to_s
(
'F'
)
else
value
.
inspect
when
BigDecimal
then
value
.
to_s
(
'F'
)
else
value
.
inspect
end
end
...
...
@@ -140,7 +140,7 @@ module AnnotateModels
old_content
.
sub!
(
/^\n?#
#{
COMPAT_PREFIX
}
.*?\n(#.*\n)*\n/
,
''
)
# Write it back
new_content
=
options
[
:position
].
to_s
==
'after'
?
(
old_content
+
"
\n
"
+
info_block
)
:
(
info_block
+
old_content
)
new_content
=
options
[
:position
].
to_s
==
'after'
?
(
old_content
+
"
\n
"
+
info_block
)
:
(
info_block
+
old_content
)
File
.
open
(
file_name
,
"wb"
)
{
|
f
|
f
.
puts
new_content
}
true
...
...
@@ -176,8 +176,8 @@ module AnnotateModels
unless
ENV
[
'exclude_tests'
]
[
File
.
join
(
UNIT_TEST_DIR
,
"
#{
model_name
}
_test.rb"
),
# test
File
.
join
(
SPEC_MODEL_DIR
,
"
#{
model_name
}
_spec.rb"
),
# spec
File
.
join
(
UNIT_TEST_DIR
,
"
#{
model_name
}
_test.rb"
),
# test
File
.
join
(
SPEC_MODEL_DIR
,
"
#{
model_name
}
_spec.rb"
),
# spec
].
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
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
...
...
@@ -186,13 +186,13 @@ module AnnotateModels
unless
ENV
[
'exclude_fixtures'
]
[
File
.
join
(
EXEMPLARS_TEST_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
EXEMPLARS_SPEC_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
BLUEPRINTS_TEST_DIR
,
"
#{
model_name
}
_blueprint.rb"
),
# Machinist Blueprints
File
.
join
(
BLUEPRINTS_SPEC_DIR
,
"
#{
model_name
}
_blueprint.rb"
),
# Machinist Blueprints
File
.
join
(
FACTORY_GIRL_TEST_DIR
,
"
#{
model_name
}
_factory.rb"
),
# Factory Girl Factories
File
.
join
(
FACTORY_GIRL_SPEC_DIR
,
"
#{
model_name
}
_factory.rb"
),
# Factory Girl Factories
].
each
do
|
file
|
File
.
join
(
EXEMPLARS_TEST_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
EXEMPLARS_SPEC_DIR
,
"
#{
model_name
}
_exemplar.rb"
),
# Object Daddy
File
.
join
(
BLUEPRINTS_TEST_DIR
,
"
#{
model_name
}
_blueprint.rb"
),
# Machinist Blueprints
File
.
join
(
BLUEPRINTS_SPEC_DIR
,
"
#{
model_name
}
_blueprint.rb"
),
# Machinist Blueprints
File
.
join
(
FACTORY_GIRL_TEST_DIR
,
"
#{
model_name
}
_factory.rb"
),
# Factory Girl Factories
File
.
join
(
FACTORY_GIRL_SPEC_DIR
,
"
#{
model_name
}
_factory.rb"
),
# Factory Girl Factories
].
each
do
|
file
|
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_fixture
))
end
FIXTURE_DIRS
.
each
do
|
dir
|
...
...
@@ -205,8 +205,8 @@ module AnnotateModels
unless
ENV
[
'exclude_factories'
]
[
File
.
join
(
FACTORY_GIRL_SPEC_DIR
,
"
#{
model_name
}
_factory.rb"
),
# spec/factories
File
.
join
(
FACTORY_GIRL_TEST_DIR
,
"
#{
model_name
}
_factory.rb"
),
# test/factories
File
.
join
(
FACTORY_GIRL_SPEC_DIR
,
"
#{
model_name
}
_factory.rb"
),
# spec/factories
File
.
join
(
FACTORY_GIRL_TEST_DIR
,
"
#{
model_name
}
_factory.rb"
),
# test/factories
].
each
do
|
file
|
annotate_one_file
(
file
,
info
,
options_with_position
(
options
,
:position_in_factory
))
end
...
...
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