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
f1fe52e2
Commit
f1fe52e2
authored
Oct 19, 2017
by
Alexander Belozerov
Committed by
Cuong Tran
Oct 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fix #345] annotate --delete should not ignore SkipSchemaAnnotations flag
parent
e315405c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
annotate_models.rb
lib/annotate/annotate_models.rb
+6
-2
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+22
-0
No files found.
lib/annotate/annotate_models.rb
View file @
f1fe52e2
...
...
@@ -12,6 +12,8 @@ module AnnotateModels
PREFIX_MD
=
'## Schema Information'
.
freeze
END_MARK
=
'== Schema Information End'
.
freeze
SKIP_ANNOTATION_PREFIX
=
'# -\*- SkipSchemaAnnotations'
.
freeze
MATCHED_TYPES
=
%w(test fixture factory serializer scaffold controller helper)
.
freeze
# File.join for windows reverse bar compat?
...
...
@@ -498,7 +500,7 @@ module AnnotateModels
def
annotate_one_file
(
file_name
,
info_block
,
position
,
options
=
{})
if
File
.
exist?
(
file_name
)
old_content
=
File
.
read
(
file_name
)
return
false
if
old_content
=~
/#
-\*- SkipSchemaAnnotations
.*\n/
return
false
if
old_content
=~
/
#
{
SKIP_ANNOTATION_PREFIX
}
.*\n/
# Ignore the Schema version line because it changes with each migration
header_pattern
=
/(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?)/
...
...
@@ -562,6 +564,8 @@ module AnnotateModels
def
remove_annotation_of_file
(
file_name
,
options
=
{})
if
File
.
exist?
(
file_name
)
content
=
File
.
read
(
file_name
)
return
false
if
content
=~
/
#{
SKIP_ANNOTATION_PREFIX
}
.*\n/
wrapper_open
=
options
[
:wrapper_open
]
?
"#
#{
options
[
:wrapper_open
]
}
\n
"
:
''
content
.
sub!
(
/(
#{
wrapper_open
}
)?
#{
annotate_pattern
(
options
)
}
/
,
''
)
...
...
@@ -767,7 +771,7 @@ module AnnotateModels
def
annotate_model_file
(
annotated
,
file
,
header
,
options
)
begin
return
false
if
/#
-\*- SkipSchemaAnnotations
.*/
=~
(
File
.
exist?
(
file
)
?
File
.
read
(
file
)
:
''
)
return
false
if
/
#
{
SKIP_ANNOTATION_PREFIX
}
.*/
=~
(
File
.
exist?
(
file
)
?
File
.
read
(
file
)
:
''
)
klass
=
get_model_class
(
file
)
do_annotate
=
klass
&&
klass
<
ActiveRecord
::
Base
&&
...
...
spec/annotate/annotate_models_spec.rb
View file @
f1fe52e2
...
...
@@ -1400,6 +1400,28 @@ class Foo < ActiveRecord::Base
end
EOS
end
it
'does not change file with #SkipSchemaAnnotations'
do
content
=
<<-
EOS
# -*- SkipSchemaAnnotations
# == Schema Information
#
# Table name: foo
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
#
class Foo < ActiveRecord::Base
end
EOS
path
=
create
'skip.rb'
,
content
AnnotateModels
.
remove_annotation_of_file
(
path
)
expect
(
content
(
path
)).
to
eq
(
content
)
end
end
describe
'#resolve_filename'
do
...
...
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