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
a29aa470
Commit
a29aa470
authored
Feb 11, 2016
by
Cuong Tran
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #339 from kamilbielawski/persisting-wrapper-open-fix
Don't leave wrapper when removing annotations
parents
09067223
c6911204
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
4 deletions
+54
-4
annotate_models.rb
lib/annotate/annotate_models.rb
+5
-4
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+49
-0
No files found.
lib/annotate/annotate_models.rb
View file @
a29aa470
...
@@ -403,10 +403,11 @@ module AnnotateModels
...
@@ -403,10 +403,11 @@ module AnnotateModels
end
end
end
end
def
remove_annotation_of_file
(
file_name
)
def
remove_annotation_of_file
(
file_name
,
options
=
{}
)
if
File
.
exist?
(
file_name
)
if
File
.
exist?
(
file_name
)
content
=
File
.
read
(
file_name
)
content
=
File
.
read
(
file_name
)
content
.
sub!
(
PATTERN
,
''
)
wrapper_open
=
options
[
:wrapper_open
]
?
"#
#{
options
[
:wrapper_open
]
}
\n
"
:
""
content
.
sub!
(
/(
#{
wrapper_open
}
)?
#{
PATTERN
}
/
,
''
)
File
.
open
(
file_name
,
'wb'
)
{
|
f
|
f
.
puts
content
}
File
.
open
(
file_name
,
'wb'
)
{
|
f
|
f
.
puts
content
}
...
@@ -623,13 +624,13 @@ module AnnotateModels
...
@@ -623,13 +624,13 @@ module AnnotateModels
model_name
=
klass
.
name
.
underscore
model_name
=
klass
.
name
.
underscore
table_name
=
klass
.
table_name
table_name
=
klass
.
table_name
model_file_name
=
file
model_file_name
=
file
deannotated_klass
=
true
if
remove_annotation_of_file
(
model_file_name
)
deannotated_klass
=
true
if
remove_annotation_of_file
(
model_file_name
,
options
)
get_patterns
(
matched_types
(
options
)).
get_patterns
(
matched_types
(
options
)).
map
{
|
f
|
resolve_filename
(
f
,
model_name
,
table_name
)
}.
map
{
|
f
|
resolve_filename
(
f
,
model_name
,
table_name
)
}.
each
do
|
f
|
each
do
|
f
|
if
File
.
exist?
(
f
)
if
File
.
exist?
(
f
)
remove_annotation_of_file
(
f
)
remove_annotation_of_file
(
f
,
options
)
deannotated_klass
=
true
deannotated_klass
=
true
end
end
end
end
...
...
spec/annotate/annotate_models_spec.rb
View file @
a29aa470
...
@@ -514,6 +514,55 @@ class Foo < ActiveRecord::Base
...
@@ -514,6 +514,55 @@ class Foo < ActiveRecord::Base
end
end
EOS
EOS
end
end
it
"should remove opening wrapper"
do
path
=
create
"opening_wrapper.rb"
,
<<-
EOS
# wrapper
# == Schema Information
#
# Table name: foo
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
#
class Foo < ActiveRecord::Base
end
EOS
AnnotateModels
.
remove_annotation_of_file
(
path
,
wrapper_open:
'wrapper'
)
expect
(
content
(
path
)).
to
eq
<<-
EOS
class Foo < ActiveRecord::Base
end
EOS
end
it
"should remove closing wrapper"
do
path
=
create
"closing_wrapper.rb"
,
<<-
EOS
class Foo < ActiveRecord::Base
end
# == Schema Information
#
# Table name: foo
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
#
# wrapper
EOS
AnnotateModels
.
remove_annotation_of_file
(
path
,
wrapper_close:
'wrapper'
)
expect
(
content
(
path
)).
to
eq
<<-
EOS
class Foo < ActiveRecord::Base
end
EOS
end
end
end
describe
'#resolve_filename'
do
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