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
f1fa3510
Commit
f1fa3510
authored
Apr 13, 2016
by
Cuong Tran
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #364 from dennisvandehoef/remove_wrapper_content
fix so that the wrapper-opening does not gets duplicated
parents
5dde3cc6
e30044e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
6 deletions
+12
-6
.rubocop_todo.yml
.rubocop_todo.yml
+1
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+11
-5
No files found.
.rubocop_todo.yml
View file @
f1fa3510
...
...
@@ -105,7 +105,7 @@ Metrics/MethodLength:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ModuleLength
:
Max
:
51
3
Max
:
51
6
# Offense count: 7
Metrics/PerceivedComplexity
:
...
...
lib/annotate/annotate_models.rb
View file @
f1fa3510
...
...
@@ -9,7 +9,6 @@ module AnnotateModels
PREFIX
=
"== Schema Information"
PREFIX_MD
=
"## Schema Information"
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 controller helper)
...
...
@@ -65,6 +64,13 @@ module AnnotateModels
NO_DEFAULT_COL_TYPES
=
%w(json jsonb)
class
<<
self
def
annotate_pattern
(
options
=
{})
if
options
[
:wrapper_open
]
return
/(?:^\n?# (?:
#{
options
[
:wrapper_open
]
}
).*\n?# (?:
#{
COMPAT_PREFIX
}
|
#{
COMPAT_PREFIX_MD
}
).*?\n(#.*\n)*\n*)|^\n?# (?:
#{
COMPAT_PREFIX
}
|
#{
COMPAT_PREFIX_MD
}
).*?\n(#.*\n)*\n*/
end
/^\n?# (?:
#{
COMPAT_PREFIX
}
|
#{
COMPAT_PREFIX_MD
}
).*?\n(#.*\n)*\n*/
end
def
model_dir
@model_dir
.
is_a?
(
Array
)
?
@model_dir
:
[
@model_dir
||
'app/models'
]
end
...
...
@@ -378,10 +384,10 @@ module AnnotateModels
return
false
else
# Replace inline the old schema info with the new schema info
new_content
=
old_content
.
sub
(
PATTERN
,
info_block
+
"
\n
"
)
new_content
=
old_content
.
sub
(
annotate_pattern
(
options
)
,
info_block
+
"
\n
"
)
if
new_content
.
end_with?
(
info_block
+
"
\n
"
)
new_content
=
old_content
.
sub
(
PATTERN
,
"
\n
"
+
info_block
)
new_content
=
old_content
.
sub
(
annotate_pattern
(
options
)
,
"
\n
"
+
info_block
)
end
wrapper_open
=
options
[
:wrapper_open
]
?
"#
#{
options
[
:wrapper_open
]
}
\n
"
:
""
...
...
@@ -391,7 +397,7 @@ module AnnotateModels
# we simply need to insert it in correct position
if
new_content
==
old_content
||
options
[
:force
]
old_content
.
sub!
(
magic_comment_matcher
,
''
)
old_content
.
sub!
(
PATTERN
,
''
)
old_content
.
sub!
(
annotate_pattern
(
options
)
,
''
)
if
%w(after bottom)
.
include?
(
options
[
position
].
to_s
)
new_content
=
magic_comments
.
join
+
(
old_content
.
rstrip
+
"
\n\n
"
+
wrapped_info_block
)
...
...
@@ -412,7 +418,7 @@ module AnnotateModels
if
File
.
exist?
(
file_name
)
content
=
File
.
read
(
file_name
)
wrapper_open
=
options
[
:wrapper_open
]
?
"#
#{
options
[
:wrapper_open
]
}
\n
"
:
""
content
.
sub!
(
/(
#{
wrapper_open
}
)?
#{
PATTERN
}
/
,
''
)
content
.
sub!
(
/(
#{
wrapper_open
}
)?
#{
annotate_pattern
(
options
)
}
/
,
''
)
File
.
open
(
file_name
,
'wb'
)
{
|
f
|
f
.
puts
content
}
...
...
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