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
31fe4c5a
Commit
31fe4c5a
authored
Jan 11, 2016
by
cuong.tran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not annotate controllers, helpers and scaffolds by default (revert to…
Do not annotate controllers, helpers and scaffolds by default (revert to behavior from previous version)
parent
64b1a343
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
21 deletions
+35
-21
annotate.rb
lib/annotate.rb
+10
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+20
-15
auto_annotate_models.rake
lib/generators/annotate/templates/auto_annotate_models.rake
+3
-3
annotate_models.rake
lib/tasks/annotate_models.rake
+2
-2
No files found.
lib/annotate.rb
View file @
31fe4c5a
...
@@ -14,6 +14,8 @@ rescue Exception
...
@@ -14,6 +14,8 @@ rescue Exception
end
end
module
Annotate
module
Annotate
TRUE_RE
=
/^(true|t|yes|y|1)$/i
##
##
# The set of available options to customize the behavior of Annotate.
# The set of available options to customize the behavior of Annotate.
#
#
...
@@ -60,7 +62,9 @@ module Annotate
...
@@ -60,7 +62,9 @@ module Annotate
end
end
end
end
TRUE_RE
=
/^(true|t|yes|y|1)$/i
##
# TODO: what is the difference between this and set_defaults?
#
def
self
.
setup_options
(
options
=
{})
def
self
.
setup_options
(
options
=
{})
POSITION_OPTIONS
.
each
do
|
key
|
POSITION_OPTIONS
.
each
do
|
key
|
options
[
key
]
=
fallback
(
ENV
[
key
.
to_s
],
ENV
[
'position'
],
'before'
)
options
[
key
]
=
fallback
(
ENV
[
key
.
to_s
],
ENV
[
'position'
],
'before'
)
...
@@ -86,6 +90,11 @@ module Annotate
...
@@ -86,6 +90,11 @@ module Annotate
options
[
:wrapper_open
]
||=
options
[
:wrapper
]
options
[
:wrapper_open
]
||=
options
[
:wrapper
]
options
[
:wrapper_close
]
||=
options
[
:wrapper
]
options
[
:wrapper_close
]
||=
options
[
:wrapper
]
# These were added in 2.7.0 but so this is to revert to old behavior by default
options
[
:exclude_scaffolds
]
=
Annotate
.
true?
(
ENV
.
fetch
(
'exclude_scaffolds'
,
'true'
))
options
[
:exclude_controllers
]
=
Annotate
.
true?
(
ENV
.
fetch
(
'exclude_controllers'
,
'true'
))
options
[
:exclude_helpers
]
=
Annotate
.
true?
(
ENV
.
fetch
(
'exclude_helpers'
,
'true'
))
return
options
return
options
end
end
...
...
lib/annotate/annotate_models.rb
View file @
31fe4c5a
...
@@ -320,7 +320,9 @@ module AnnotateModels
...
@@ -320,7 +320,9 @@ module AnnotateModels
# a schema info block (a comment starting with "== Schema Information"), check if it
# a schema info block (a comment starting with "== Schema Information"), check if it
# matches the block that is already there. If so, leave it be. If not, remove the old
# matches the block that is already there. If so, leave it be. If not, remove the old
# info block and write a new one.
# info block and write a new one.
# Returns true or false depending on whether the file was modified.
#
# == Returns:
# true or false depending on whether the file was modified.
#
#
# === Options (opts)
# === Options (opts)
# :force<Symbol>:: whether to update the file even if it doesn't seem to need it.
# :force<Symbol>:: whether to update the file even if it doesn't seem to need it.
...
@@ -394,8 +396,6 @@ module AnnotateModels
...
@@ -394,8 +396,6 @@ module AnnotateModels
# info block (basically a comment containing information
# info block (basically a comment containing information
# on the columns and their types) and put it at the front
# on the columns and their types) and put it at the front
# of the model and fixture source files.
# of the model and fixture source files.
# Returns true or false depending on whether the source
# files were modified.
#
#
# === Options (opts)
# === Options (opts)
# :position_in_class<Symbol>:: where to place the annotated section in model file
# :position_in_class<Symbol>:: where to place the annotated section in model file
...
@@ -411,16 +411,19 @@ module AnnotateModels
...
@@ -411,16 +411,19 @@ module AnnotateModels
# :exclude_controllers<Symbol>:: whether to skip modification of controller files
# :exclude_controllers<Symbol>:: whether to skip modification of controller files
# :exclude_helpers<Symbol>:: whether to skip modification of helper files
# :exclude_helpers<Symbol>:: whether to skip modification of helper files
#
#
# == Returns:
# an array of file names that were annotated.
#
def
annotate
(
klass
,
file
,
header
,
options
=
{})
def
annotate
(
klass
,
file
,
header
,
options
=
{})
begin
begin
info
=
get_schema_info
(
klass
,
header
,
options
)
info
=
get_schema_info
(
klass
,
header
,
options
)
did_annotate
=
false
model_name
=
klass
.
name
.
underscore
model_name
=
klass
.
name
.
underscore
table_name
=
klass
.
table_name
table_name
=
klass
.
table_name
model_file_name
=
File
.
join
(
file
)
model_file_name
=
File
.
join
(
file
)
annotated
=
[]
if
annotate_one_file
(
model_file_name
,
info
,
:position_in_class
,
options_with_position
(
options
,
:position_in_class
))
if
annotate_one_file
(
model_file_name
,
info
,
:position_in_class
,
options_with_position
(
options
,
:position_in_class
))
did_annotate
=
tru
e
annotated
<<
model_file_nam
e
end
end
MATCHED_TYPES
.
each
do
|
key
|
MATCHED_TYPES
.
each
do
|
key
|
...
@@ -428,18 +431,21 @@ module AnnotateModels
...
@@ -428,18 +431,21 @@ module AnnotateModels
position_key
=
"position_in_
#{
key
}
"
.
to_sym
position_key
=
"position_in_
#{
key
}
"
.
to_sym
unless
options
[
exclusion_key
]
unless
options
[
exclusion_key
]
did_annotate
=
self
.
get_patterns
(
key
).
self
.
get_patterns
(
key
).
map
{
|
f
|
resolve_filename
(
f
,
model_name
,
table_name
)
}.
map
{
|
f
|
resolve_filename
(
f
,
model_name
,
table_name
)
}.
map
{
|
f
|
annotate_one_file
(
f
,
info
,
position_key
,
options_with_position
(
options
,
position_key
))
}.
each
{
|
f
|
detect
{
|
result
|
result
}
||
did_annotate
if
annotate_one_file
(
f
,
info
,
position_key
,
options_with_position
(
options
,
position_key
))
annotated
<<
f
end
}
end
end
end
end
return
did_annotate
rescue
Exception
=>
e
rescue
Exception
=>
e
puts
"Unable to annotate
#{
file
}
:
#{
e
.
message
}
"
puts
"Unable to annotate
#{
file
}
:
#{
e
.
message
}
"
puts
"
\t
"
+
e
.
backtrace
.
join
(
"
\n\t
"
)
if
options
[
:trace
]
puts
"
\t
"
+
e
.
backtrace
.
join
(
"
\n\t
"
)
if
options
[
:trace
]
end
end
return
annotated
end
end
# position = :position_in_fixture or :position_in_class
# position = :position_in_fixture or :position_in_class
...
@@ -537,9 +543,10 @@ module AnnotateModels
...
@@ -537,9 +543,10 @@ module AnnotateModels
self
.
root_dir
=
options
[
:root_dir
]
if
options
[
:root_dir
]
self
.
root_dir
=
options
[
:root_dir
]
if
options
[
:root_dir
]
annotated
=
[]
annotated
=
[]
get_model_files
(
options
).
each
do
|
fil
e
|
get_model_files
(
options
).
each
do
|
path
,
filenam
e
|
annotate_model_file
(
annotated
,
File
.
join
(
fil
e
),
header
,
options
)
annotate_model_file
(
annotated
,
File
.
join
(
path
,
filenam
e
),
header
,
options
)
end
end
if
annotated
.
empty?
if
annotated
.
empty?
puts
"Model files unchanged."
puts
"Model files unchanged."
else
else
...
@@ -552,9 +559,7 @@ module AnnotateModels
...
@@ -552,9 +559,7 @@ module AnnotateModels
return
false
if
(
/# -\*- SkipSchemaAnnotations.*/
=~
(
File
.
exist?
(
file
)
?
File
.
read
(
file
)
:
''
)
)
return
false
if
(
/# -\*- SkipSchemaAnnotations.*/
=~
(
File
.
exist?
(
file
)
?
File
.
read
(
file
)
:
''
)
)
klass
=
get_model_class
(
file
)
klass
=
get_model_class
(
file
)
if
klass
&&
klass
<
ActiveRecord
::
Base
&&
!
klass
.
abstract_class?
&&
klass
.
table_exists?
if
klass
&&
klass
<
ActiveRecord
::
Base
&&
!
klass
.
abstract_class?
&&
klass
.
table_exists?
if
annotate
(
klass
,
file
,
header
,
options
)
annotated
.
concat
(
annotate
(
klass
,
file
,
header
,
options
))
annotated
<<
file
end
end
end
rescue
BadModelFileError
=>
e
rescue
BadModelFileError
=>
e
unless
options
[
:ignore_unknown_models
]
unless
options
[
:ignore_unknown_models
]
...
...
lib/generators/annotate/templates/auto_annotate_models.rake
View file @
31fe4c5a
...
@@ -24,9 +24,9 @@ if Rails.env.development?
...
@@ -24,9 +24,9 @@ if Rails.env.development?
'exclude_fixtures'
=>
'false'
,
'exclude_fixtures'
=>
'false'
,
'exclude_factories'
=>
'false'
,
'exclude_factories'
=>
'false'
,
'exclude_serializers'
=>
'false'
,
'exclude_serializers'
=>
'false'
,
'exclude_scaffolds'
=>
'
fals
e'
,
'exclude_scaffolds'
=>
'
tru
e'
,
'exclude_controllers'
=>
'
fals
e'
,
'exclude_controllers'
=>
'
tru
e'
,
'exclude_helpers'
=>
'
fals
e'
,
'exclude_helpers'
=>
'
tru
e'
,
'ignore_model_sub_dir'
=>
'false'
,
'ignore_model_sub_dir'
=>
'false'
,
'ignore_columns'
=>
nil
,
'ignore_columns'
=>
nil
,
'ignore_routes'
=>
nil
,
'ignore_routes'
=>
nil
,
...
...
lib/tasks/annotate_models.rake
View file @
31fe4c5a
...
@@ -29,8 +29,8 @@ task :annotate_models => :environment do
...
@@ -29,8 +29,8 @@ task :annotate_models => :environment do
options
[
:exclude_fixtures
]
=
Annotate
.
true?
(
ENV
[
'exclude_fixtures'
])
options
[
:exclude_fixtures
]
=
Annotate
.
true?
(
ENV
[
'exclude_fixtures'
])
options
[
:exclude_serializers
]
=
Annotate
.
true?
(
ENV
[
'exclude_serializers'
])
options
[
:exclude_serializers
]
=
Annotate
.
true?
(
ENV
[
'exclude_serializers'
])
options
[
:exclude_scaffolds
]
=
Annotate
.
true?
(
ENV
[
'exclude_scaffolds'
])
options
[
:exclude_scaffolds
]
=
Annotate
.
true?
(
ENV
[
'exclude_scaffolds'
])
options
[
:exclude_controllers
]
=
Annotate
.
true?
(
ENV
[
'exclude_controllers'
]
)
options
[
:exclude_controllers
]
=
Annotate
.
true?
(
ENV
.
fetch
(
'exclude_controllers'
,
'true'
)
)
options
[
:exclude_helpers
]
=
Annotate
.
true?
(
ENV
[
'exclude_helpers'
]
)
options
[
:exclude_helpers
]
=
Annotate
.
true?
(
ENV
.
fetch
(
'exclude_helpers'
,
'true'
)
)
options
[
:ignore_model_sub_dir
]
=
Annotate
.
true?
(
ENV
[
'ignore_model_sub_dir'
])
options
[
:ignore_model_sub_dir
]
=
Annotate
.
true?
(
ENV
[
'ignore_model_sub_dir'
])
options
[
:format_bare
]
=
Annotate
.
true?
(
ENV
[
'format_bare'
])
options
[
:format_bare
]
=
Annotate
.
true?
(
ENV
[
'format_bare'
])
options
[
:format_rdoc
]
=
Annotate
.
true?
(
ENV
[
'format_rdoc'
])
options
[
:format_rdoc
]
=
Annotate
.
true?
(
ENV
[
'format_rdoc'
])
...
...
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