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
Hide 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
end
module
Annotate
TRUE_RE
=
/^(true|t|yes|y|1)$/i
##
# The set of available options to customize the behavior of Annotate.
#
...
...
@@ -60,7 +62,9 @@ module Annotate
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
=
{})
POSITION_OPTIONS
.
each
do
|
key
|
options
[
key
]
=
fallback
(
ENV
[
key
.
to_s
],
ENV
[
'position'
],
'before'
)
...
...
@@ -86,6 +90,11 @@ module Annotate
options
[
:wrapper_open
]
||=
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
end
...
...
lib/annotate/annotate_models.rb
View file @
31fe4c5a
...
...
@@ -320,7 +320,9 @@ module AnnotateModels
# 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
# 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)
# :force<Symbol>:: whether to update the file even if it doesn't seem to need it.
...
...
@@ -394,8 +396,6 @@ module AnnotateModels
# info block (basically a comment containing information
# on the columns and their types) and put it at the front
# of the model and fixture source files.
# Returns true or false depending on whether the source
# files were modified.
#
# === Options (opts)
# :position_in_class<Symbol>:: where to place the annotated section in model file
...
...
@@ -411,16 +411,19 @@ module AnnotateModels
# :exclude_controllers<Symbol>:: whether to skip modification of controller 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
=
{})
begin
info
=
get_schema_info
(
klass
,
header
,
options
)
did_annotate
=
false
model_name
=
klass
.
name
.
underscore
table_name
=
klass
.
table_name
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
))
did_annotate
=
tru
e
annotated
<<
model_file_nam
e
end
MATCHED_TYPES
.
each
do
|
key
|
...
...
@@ -428,18 +431,21 @@ module AnnotateModels
position_key
=
"position_in_
#{
key
}
"
.
to_sym
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
|
annotate_one_file
(
f
,
info
,
position_key
,
options_with_position
(
options
,
position_key
))
}.
detect
{
|
result
|
result
}
||
did_annotate
each
{
|
f
|
if
annotate_one_file
(
f
,
info
,
position_key
,
options_with_position
(
options
,
position_key
))
annotated
<<
f
end
}
end
end
return
did_annotate
rescue
Exception
=>
e
puts
"Unable to annotate
#{
file
}
:
#{
e
.
message
}
"
puts
"
\t
"
+
e
.
backtrace
.
join
(
"
\n\t
"
)
if
options
[
:trace
]
end
return
annotated
end
# position = :position_in_fixture or :position_in_class
...
...
@@ -537,9 +543,10 @@ module AnnotateModels
self
.
root_dir
=
options
[
:root_dir
]
if
options
[
:root_dir
]
annotated
=
[]
get_model_files
(
options
).
each
do
|
fil
e
|
annotate_model_file
(
annotated
,
File
.
join
(
fil
e
),
header
,
options
)
get_model_files
(
options
).
each
do
|
path
,
filenam
e
|
annotate_model_file
(
annotated
,
File
.
join
(
path
,
filenam
e
),
header
,
options
)
end
if
annotated
.
empty?
puts
"Model files unchanged."
else
...
...
@@ -552,9 +559,7 @@ module AnnotateModels
return
false
if
(
/# -\*- SkipSchemaAnnotations.*/
=~
(
File
.
exist?
(
file
)
?
File
.
read
(
file
)
:
''
)
)
klass
=
get_model_class
(
file
)
if
klass
&&
klass
<
ActiveRecord
::
Base
&&
!
klass
.
abstract_class?
&&
klass
.
table_exists?
if
annotate
(
klass
,
file
,
header
,
options
)
annotated
<<
file
end
annotated
.
concat
(
annotate
(
klass
,
file
,
header
,
options
))
end
rescue
BadModelFileError
=>
e
unless
options
[
:ignore_unknown_models
]
...
...
lib/generators/annotate/templates/auto_annotate_models.rake
View file @
31fe4c5a
...
...
@@ -24,9 +24,9 @@ if Rails.env.development?
'exclude_fixtures'
=>
'false'
,
'exclude_factories'
=>
'false'
,
'exclude_serializers'
=>
'false'
,
'exclude_scaffolds'
=>
'
fals
e'
,
'exclude_controllers'
=>
'
fals
e'
,
'exclude_helpers'
=>
'
fals
e'
,
'exclude_scaffolds'
=>
'
tru
e'
,
'exclude_controllers'
=>
'
tru
e'
,
'exclude_helpers'
=>
'
tru
e'
,
'ignore_model_sub_dir'
=>
'false'
,
'ignore_columns'
=>
nil
,
'ignore_routes'
=>
nil
,
...
...
lib/tasks/annotate_models.rake
View file @
31fe4c5a
...
...
@@ -29,8 +29,8 @@ task :annotate_models => :environment do
options
[
:exclude_fixtures
]
=
Annotate
.
true?
(
ENV
[
'exclude_fixtures'
])
options
[
:exclude_serializers
]
=
Annotate
.
true?
(
ENV
[
'exclude_serializers'
])
options
[
:exclude_scaffolds
]
=
Annotate
.
true?
(
ENV
[
'exclude_scaffolds'
])
options
[
:exclude_controllers
]
=
Annotate
.
true?
(
ENV
[
'exclude_controllers'
]
)
options
[
:exclude_helpers
]
=
Annotate
.
true?
(
ENV
[
'exclude_helpers'
]
)
options
[
:exclude_controllers
]
=
Annotate
.
true?
(
ENV
.
fetch
(
'exclude_controllers'
,
'true'
)
)
options
[
:exclude_helpers
]
=
Annotate
.
true?
(
ENV
.
fetch
(
'exclude_helpers'
,
'true'
)
)
options
[
:ignore_model_sub_dir
]
=
Annotate
.
true?
(
ENV
[
'ignore_model_sub_dir'
])
options
[
:format_bare
]
=
Annotate
.
true?
(
ENV
[
'format_bare'
])
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