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
bcecce3f
Commit
bcecce3f
authored
Nov 30, 2015
by
djsegal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add root_dir param to allow multiple root dirs
parent
6fd2fb67
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
45 deletions
+78
-45
annotate
bin/annotate
+5
-0
annotate.rb
lib/annotate.rb
+5
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+65
-44
auto_annotate_models.rake
lib/generators/annotate/templates/auto_annotate_models.rake
+1
-0
annotate_models.rake
lib/tasks/annotate_models.rake
+2
-0
No files found.
bin/annotate
View file @
bcecce3f
...
...
@@ -129,6 +129,11 @@ OptionParser.new do |opts|
ENV
[
'model_dir'
]
=
dir
end
opts
.
on
(
'--root-dir dir'
,
"Annotate files stored within root dir projects, separate multiple dirs with comas"
)
do
|
dir
|
ENV
[
'root_dir'
]
=
dir
end
opts
.
on
(
'--ignore-model-subdirects'
,
"Ignore subdirectories of the models directory"
)
do
|
dir
|
ENV
[
'ignore_model_sub_dir'
]
=
"yes"
...
...
lib/annotate.rb
View file @
bcecce3f
...
...
@@ -33,7 +33,7 @@ module Annotate
:ignore_columns
,
:skip_on_db_migrate
,
:wrapper_open
,
:wrapper_close
,
:wrapper
]
PATH_OPTIONS
=
[
:require
,
:model_dir
:require
,
:model_dir
,
:root_dir
]
...
...
@@ -76,6 +76,10 @@ module Annotate
options
[
:model_dir
]
=
[
'app/models'
]
end
if
(
options
[
:root_dir
].
empty?
)
options
[
:root_dir
]
=
[
''
]
end
options
[
:wrapper_open
]
||=
options
[
:wrapper
]
options
[
:wrapper_close
]
||=
options
[
:wrapper
]
...
...
lib/annotate/annotate_models.rb
View file @
bcecce3f
...
...
@@ -9,6 +9,8 @@ module AnnotateModels
END_MARK
=
"== Schema Information End"
PATTERN
=
/^\r?\n?# (?:
#{
COMPAT_PREFIX
}
|
#{
COMPAT_PREFIX_MD
}
).*?\r?\n(#.*\r?\n)*(\r?\n)*/
MATCHED_TYPES
=
%w(test fixture factory serializer scaffold)
# File.join for windows reverse bar compat?
# I dont use windows, can`t test
UNIT_TEST_DIR
=
File
.
join
(
"test"
,
"unit"
)
...
...
@@ -44,46 +46,6 @@ module AnnotateModels
SERIALIZERS_TEST_DIR
=
File
.
join
(
"test"
,
"serializers"
)
SERIALIZERS_SPEC_DIR
=
File
.
join
(
"spec"
,
"serializers"
)
TEST_PATTERNS
=
[
File
.
join
(
UNIT_TEST_DIR
,
"%MODEL_NAME%_test.rb"
),
File
.
join
(
MODEL_TEST_DIR
,
"%MODEL_NAME%_test.rb"
),
File
.
join
(
SPEC_MODEL_DIR
,
"%MODEL_NAME%_spec.rb"
),
]
FIXTURE_PATTERNS
=
[
File
.
join
(
FIXTURE_TEST_DIR
,
"%TABLE_NAME%.yml"
),
File
.
join
(
FIXTURE_SPEC_DIR
,
"%TABLE_NAME%.yml"
),
File
.
join
(
FIXTURE_TEST_DIR
,
"%PLURALIZED_MODEL_NAME%.yml"
),
File
.
join
(
FIXTURE_SPEC_DIR
,
"%PLURALIZED_MODEL_NAME%.yml"
),
]
SCAFFOLD_PATTERNS
=
[
File
.
join
(
CONTROLLER_TEST_DIR
,
"%PLURALIZED_MODEL_NAME%_controller_test.rb"
),
File
.
join
(
CONTROLLER_SPEC_DIR
,
"%PLURALIZED_MODEL_NAME%_controller_spec.rb"
),
File
.
join
(
REQUEST_SPEC_DIR
,
"%PLURALIZED_MODEL_NAME%_spec.rb"
),
File
.
join
(
ROUTING_SPEC_DIR
,
"%PLURALIZED_MODEL_NAME%_routing_spec.rb"
),
]
FACTORY_PATTERNS
=
[
File
.
join
(
EXEMPLARS_TEST_DIR
,
"%MODEL_NAME%_exemplar.rb"
),
File
.
join
(
EXEMPLARS_SPEC_DIR
,
"%MODEL_NAME%_exemplar.rb"
),
File
.
join
(
BLUEPRINTS_TEST_DIR
,
"%MODEL_NAME%_blueprint.rb"
),
File
.
join
(
BLUEPRINTS_SPEC_DIR
,
"%MODEL_NAME%_blueprint.rb"
),
File
.
join
(
FACTORY_GIRL_TEST_DIR
,
"%MODEL_NAME%_factory.rb"
),
# (old style)
File
.
join
(
FACTORY_GIRL_SPEC_DIR
,
"%MODEL_NAME%_factory.rb"
),
# (old style)
File
.
join
(
FACTORY_GIRL_TEST_DIR
,
"%TABLE_NAME%.rb"
),
# (new style)
File
.
join
(
FACTORY_GIRL_SPEC_DIR
,
"%TABLE_NAME%.rb"
),
# (new style)
File
.
join
(
FABRICATORS_TEST_DIR
,
"%MODEL_NAME%_fabricator.rb"
),
File
.
join
(
FABRICATORS_SPEC_DIR
,
"%MODEL_NAME%_fabricator.rb"
),
]
SERIALIZER_PATTERNS
=
[
File
.
join
(
SERIALIZERS_DIR
,
"%MODEL_NAME%_serializer.rb"
),
File
.
join
(
SERIALIZERS_TEST_DIR
,
"%MODEL_NAME%_serializer_spec.rb"
),
File
.
join
(
SERIALIZERS_SPEC_DIR
,
"%MODEL_NAME%_serializer_spec.rb"
)
]
# Don't show limit (#) on these column types
# Example: show "integer" instead of "integer(4)"
NO_LIMIT_COL_TYPES
=
[
"integer"
,
"boolean"
]
...
...
@@ -97,6 +59,64 @@ module AnnotateModels
@model_dir
=
dir
end
def
root_dir
@root_dir
.
is_a?
(
Array
)
?
@root_dir
:
[
@root_dir
||
""
]
end
def
root_dir
=
(
dir
)
@root_dir
=
dir
end
def
get_patterns
(
pattern_types
=
MATCHED_TYPES
)
current_patterns
=
[]
root_dir
.
each
do
|
root_directory
|
Array
(
pattern_types
).
each
do
|
pattern_type
|
current_patterns
+=
case
pattern_type
when
'test'
[
File
.
join
(
root_directory
,
UNIT_TEST_DIR
,
"%MODEL_NAME%_test.rb"
),
File
.
join
(
root_directory
,
MODEL_TEST_DIR
,
"%MODEL_NAME%_test.rb"
),
File
.
join
(
root_directory
,
SPEC_MODEL_DIR
,
"%MODEL_NAME%_spec.rb"
),
]
when
'fixture'
[
File
.
join
(
root_directory
,
FIXTURE_TEST_DIR
,
"%TABLE_NAME%.yml"
),
File
.
join
(
root_directory
,
FIXTURE_SPEC_DIR
,
"%TABLE_NAME%.yml"
),
File
.
join
(
root_directory
,
FIXTURE_TEST_DIR
,
"%PLURALIZED_MODEL_NAME%.yml"
),
File
.
join
(
root_directory
,
FIXTURE_SPEC_DIR
,
"%PLURALIZED_MODEL_NAME%.yml"
),
]
when
'scaffold'
[
File
.
join
(
root_directory
,
CONTROLLER_TEST_DIR
,
"%PLURALIZED_MODEL_NAME%_controller_test.rb"
),
File
.
join
(
root_directory
,
CONTROLLER_SPEC_DIR
,
"%PLURALIZED_MODEL_NAME%_controller_spec.rb"
),
File
.
join
(
root_directory
,
REQUEST_SPEC_DIR
,
"%PLURALIZED_MODEL_NAME%_spec.rb"
),
File
.
join
(
root_directory
,
ROUTING_SPEC_DIR
,
"%PLURALIZED_MODEL_NAME%_routing_spec.rb"
),
]
when
'factory'
[
File
.
join
(
root_directory
,
EXEMPLARS_TEST_DIR
,
"%MODEL_NAME%_exemplar.rb"
),
File
.
join
(
root_directory
,
EXEMPLARS_SPEC_DIR
,
"%MODEL_NAME%_exemplar.rb"
),
File
.
join
(
root_directory
,
BLUEPRINTS_TEST_DIR
,
"%MODEL_NAME%_blueprint.rb"
),
File
.
join
(
root_directory
,
BLUEPRINTS_SPEC_DIR
,
"%MODEL_NAME%_blueprint.rb"
),
File
.
join
(
root_directory
,
FACTORY_GIRL_TEST_DIR
,
"%MODEL_NAME%_factory.rb"
),
# (old style)
File
.
join
(
root_directory
,
FACTORY_GIRL_SPEC_DIR
,
"%MODEL_NAME%_factory.rb"
),
# (old style)
File
.
join
(
root_directory
,
FACTORY_GIRL_TEST_DIR
,
"%TABLE_NAME%.rb"
),
# (new style)
File
.
join
(
root_directory
,
FACTORY_GIRL_SPEC_DIR
,
"%TABLE_NAME%.rb"
),
# (new style)
File
.
join
(
root_directory
,
FABRICATORS_TEST_DIR
,
"%MODEL_NAME%_fabricator.rb"
),
File
.
join
(
root_directory
,
FABRICATORS_SPEC_DIR
,
"%MODEL_NAME%_fabricator.rb"
),
]
when
'serializer'
[
File
.
join
(
root_directory
,
SERIALIZERS_DIR
,
"%MODEL_NAME%_serializer.rb"
),
File
.
join
(
root_directory
,
SERIALIZERS_TEST_DIR
,
"%MODEL_NAME%_serializer_spec.rb"
),
File
.
join
(
root_directory
,
SERIALIZERS_SPEC_DIR
,
"%MODEL_NAME%_serializer_spec.rb"
)
]
end
end
end
current_patterns
.
map
{
|
p
|
p
.
sub
(
/^[\/]*/
,
''
)
}
end
# Simple quoting for the default column value
def
quote
(
value
)
case
value
...
...
@@ -371,13 +391,12 @@ module AnnotateModels
did_annotate
=
true
end
%w(test fixture factory serializer scaffold)
.
each
do
|
key
|
MATCHED_TYPES
.
each
do
|
key
|
exclusion_key
=
"exclude_
#{
key
.
pluralize
}
"
.
to_sym
patterns_constant
=
"
#{
key
.
upcase
}
_PATTERNS"
.
to_sym
position_key
=
"position_in_
#{
key
}
"
.
to_sym
unless
options
[
exclusion_key
]
did_annotate
=
self
.
const_get
(
patterns_constant
).
did_annotate
=
self
.
get_patterns
(
key
).
map
{
|
file
|
resolve_filename
(
file
,
model_name
,
table_name
)
}.
map
{
|
file
|
annotate_one_file
(
file
,
info
,
position_key
,
options_with_position
(
options
,
position_key
))
}.
detect
{
|
result
|
result
}
||
did_annotate
...
...
@@ -483,6 +502,7 @@ module AnnotateModels
end
self
.
model_dir
=
options
[
:model_dir
]
if
options
[
:model_dir
]
self
.
root_dir
=
options
[
:root_dir
]
if
options
[
:root_dir
]
annotated
=
[]
get_model_files
(
options
).
each
do
|
file
|
...
...
@@ -512,6 +532,7 @@ module AnnotateModels
def
remove_annotations
(
options
=
{})
self
.
model_dir
=
options
[
:model_dir
]
if
options
[
:model_dir
]
self
.
root_dir
=
options
[
:root_dir
]
if
options
[
:root_dir
]
deannotated
=
[]
deannotated_klass
=
false
get_model_files
(
options
).
each
do
|
file
|
...
...
@@ -524,7 +545,7 @@ module AnnotateModels
model_file_name
=
file
deannotated_klass
=
true
if
(
remove_annotation_of_file
(
model_file_name
))
(
TEST_PATTERNS
+
SCAFFOLD_PATTERNS
+
FIXTURE_PATTERNS
+
FACTORY_PATTERNS
+
SERIALIZER_PATTERNS
)
.
get_patterns
.
map
{
|
file
|
resolve_filename
(
file
,
model_name
,
table_name
)
}.
each
do
|
file
|
if
File
.
exist?
(
file
)
...
...
lib/generators/annotate/templates/auto_annotate_models.rake
View file @
bcecce3f
...
...
@@ -16,6 +16,7 @@ if Rails.env.development?
'show_indexes'
=>
'true'
,
'simple_indexes'
=>
'false'
,
'model_dir'
=>
'app/models'
,
'root_dir'
=>
''
,
'include_version'
=>
'false'
,
'require'
=>
''
,
'exclude_tests'
=>
'false'
,
...
...
lib/tasks/annotate_models.rake
View file @
bcecce3f
...
...
@@ -21,6 +21,7 @@ task :annotate_models => :environment do
options
[
:show_indexes
]
=
Annotate
.
true?
(
ENV
[
'show_indexes'
])
options
[
:simple_indexes
]
=
Annotate
.
true?
(
ENV
[
'simple_indexes'
])
options
[
:model_dir
]
=
ENV
[
'model_dir'
]
?
ENV
[
'model_dir'
].
split
(
','
)
:
[
'app/models'
]
options
[
:root_dir
]
=
ENV
[
'root_dir'
]
?
ENV
[
'root_dir'
].
split
(
','
)
:
[
''
]
options
[
:include_version
]
=
Annotate
.
true?
(
ENV
[
'include_version'
])
options
[
:require
]
=
ENV
[
'require'
]
?
ENV
[
'require'
].
split
(
','
)
:
[]
options
[
:exclude_tests
]
=
Annotate
.
true?
(
ENV
[
'exclude_tests'
])
...
...
@@ -48,6 +49,7 @@ task :remove_annotation => :environment do
options
=
{
:is_rake
=>
true
}
options
[
:model_dir
]
=
ENV
[
'model_dir'
]
options
[
:root_dir
]
=
ENV
[
'root_dir'
]
options
[
:require
]
=
ENV
[
'require'
]
?
ENV
[
'require'
].
split
(
','
)
:
[]
options
[
:trace
]
=
Annotate
.
true?
(
ENV
[
'trace'
])
AnnotateModels
.
remove_annotations
(
options
)
...
...
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