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
4a8e2a03
Commit
4a8e2a03
authored
Apr 06, 2011
by
Ben Langfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the ability to ignore subdirectories of the models dir
parent
9c68c8c9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
20 deletions
+29
-20
annotate
bin/annotate
+15
-10
annotate_models.rb
lib/annotate/annotate_models.rb
+14
-10
No files found.
bin/annotate
View file @
4a8e2a03
...
@@ -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,11 +43,16 @@ OptionParser.new do |opts|
...
@@ -43,11 +43,16 @@ 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
opts
.
on
(
'--ignore-model-subdirectories'
,
"Ignore subdirectories of the models directory"
)
do
|
dir
|
ENV
[
'ignore_model_sub_dir'
]
=
"yes"
end
opts
.
on
(
'-R'
,
'--require path'
,
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'
]
if
ENV
[
'require'
]
...
...
lib/annotate/annotate_models.rb
View file @
4a8e2a03
...
@@ -163,12 +163,12 @@ module AnnotateModels
...
@@ -163,12 +163,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
...
@@ -179,21 +179,21 @@ module AnnotateModels
...
@@ -179,21 +179,21 @@ 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
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
]))
...
@@ -211,7 +211,11 @@ module AnnotateModels
...
@@ -211,7 +211,11 @@ module AnnotateModels
if
models
.
empty?
if
models
.
empty?
begin
begin
Dir
.
chdir
(
model_dir
)
do
Dir
.
chdir
(
model_dir
)
do
models
=
Dir
[
"**/*.rb"
]
models
=
if
ENV
[
'ignore_model_sub_dir'
]
Dir
[
"*.rb"
]
else
Dir
[
"**/*.rb"
]
end
end
end
rescue
SystemCallError
rescue
SystemCallError
puts
"No models found in directory '
#{
model_dir
}
'."
puts
"No models found in directory '
#{
model_dir
}
'."
...
@@ -274,7 +278,7 @@ module AnnotateModels
...
@@ -274,7 +278,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?
...
@@ -303,12 +307,12 @@ module AnnotateModels
...
@@ -303,12 +307,12 @@ 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
end
end
rescue
Exception
=>
e
rescue
Exception
=>
e
puts
"Unable to annotate
#{
file
}
:
#{
e
.
message
}
"
puts
"Unable to annotate
#{
file
}
:
#{
e
.
message
}
"
...
...
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