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
b1f9489c
Commit
b1f9489c
authored
7 years ago
by
motot
Committed by
Cuong Tran
7 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support database comment for rails 5 (#459)
Support Database Comment for Rails 5 Added with_comment options
parent
53941460
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
11 deletions
+84
-11
.rubocop_todo.yml
.rubocop_todo.yml
+4
-4
annotate_models.rb
lib/annotate/annotate_models.rb
+12
-5
auto_annotate_models.rake
lib/generators/annotate/templates/auto_annotate_models.rake
+2
-1
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+66
-1
No files found.
.rubocop_todo.yml
View file @
b1f9489c
...
...
@@ -103,7 +103,7 @@ Lint/UselessAccessModifier:
# Offense count: 17
Metrics/AbcSize
:
Max
:
1
46
Max
:
1
59
# Offense count: 3
# Configuration parameters: CountComments.
...
...
@@ -116,7 +116,7 @@ Metrics/BlockNesting:
# Offense count: 8
Metrics/CyclomaticComplexity
:
Max
:
37
Max
:
42
# Offense count: 350
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
...
...
@@ -127,7 +127,7 @@ Metrics/LineLength:
# Offense count: 24
# Configuration parameters: CountComments.
Metrics/MethodLength
:
Max
:
7
1
Max
:
7
9
# Offense count: 1
# Configuration parameters: CountComments.
...
...
@@ -136,7 +136,7 @@ Metrics/ModuleLength:
# Offense count: 7
Metrics/PerceivedComplexity
:
Max
:
4
2
Max
:
4
8
# Offense count: 1
Style/AccessorMethodName
:
...
...
This diff is collapsed.
Click to expand it.
lib/annotate/annotate_models.rb
View file @
b1f9489c
...
...
@@ -208,6 +208,9 @@ module AnnotateModels
info
<<
get_schema_header_text
(
klass
,
options
)
max_size
=
klass
.
column_names
.
map
(
&
:size
).
max
||
0
with_comment
=
options
[
:with_comment
]
&&
klass
.
columns
.
first
.
respond_to?
(
:comment
)
max_size
=
klass
.
columns
.
map
{
|
col
|
col
.
name
.
size
+
col
.
comment
.
size
}.
max
||
0
if
with_comment
max_size
+=
2
if
with_comment
max_size
+=
options
[
:format_rdoc
]
?
5
:
1
md_names_overhead
=
6
md_type_allowance
=
18
...
...
@@ -271,15 +274,19 @@ module AnnotateModels
end
end
end
col_name
=
if
with_comment
"
#{
col
.
name
}
(
#{
col
.
comment
}
)"
else
col
.
name
end
if
options
[
:format_rdoc
]
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s<tt>%s</tt>"
,
"*
#{
col
.
name
}
*::"
,
attrs
.
unshift
(
col_type
).
join
(
", "
)).
rstrip
+
"
\n
"
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s<tt>%s</tt>"
,
"*
#{
col
_
name
}
*::"
,
attrs
.
unshift
(
col_type
).
join
(
", "
)).
rstrip
+
"
\n
"
elsif
options
[
:format_markdown
]
name_remainder
=
max_size
-
col
.
name
.
length
name_remainder
=
max_size
-
col
_
name
.
length
type_remainder
=
(
md_type_allowance
-
2
)
-
col_type
.
length
info
<<
(
sprintf
(
"# **`%s`**%
#{
name_remainder
}
s | `%s`%
#{
type_remainder
}
s | `%s`"
,
col
.
name
,
" "
,
col_type
,
" "
,
attrs
.
join
(
", "
).
rstrip
)).
gsub
(
'``'
,
' '
).
rstrip
+
"
\n
"
info
<<
(
sprintf
(
"# **`%s`**%
#{
name_remainder
}
s | `%s`%
#{
type_remainder
}
s | `%s`"
,
col
_
name
,
" "
,
col_type
,
" "
,
attrs
.
join
(
", "
).
rstrip
)).
gsub
(
'``'
,
' '
).
rstrip
+
"
\n
"
else
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s:%-
#{
bare_type_allowance
}
.
#{
bare_type_allowance
}
s %s"
,
col
.
name
,
col_type
,
attrs
.
join
(
", "
)).
rstrip
+
"
\n
"
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s:%-
#{
bare_type_allowance
}
.
#{
bare_type_allowance
}
s %s"
,
col
_
name
,
col_type
,
attrs
.
join
(
", "
)).
rstrip
+
"
\n
"
end
end
...
...
This diff is collapsed.
Click to expand it.
lib/generators/annotate/templates/auto_annotate_models.rake
View file @
b1f9489c
...
...
@@ -44,7 +44,8 @@ if Rails.env.development?
'force'
=>
'false'
,
'trace'
=>
'false'
,
'wrapper_open'
=>
nil
,
'wrapper_close'
=>
nil
'wrapper_close'
=>
nil
,
'with_comment'
=>
true
)
end
...
...
This diff is collapsed.
Click to expand it.
spec/annotate/annotate_models_spec.rb
View file @
b1f9489c
...
...
@@ -494,7 +494,7 @@ EOS
[
:notes
,
:text
,
{
limit:
55
}]
]
it
'should work with options = #{options}'
do
it
"should work with options =
#{
options
}
"
do
with_columns
=
(
options
.
delete
(
:with_columns
)
||
default_columns
).
map
do
|
column
|
mock_column
(
column
[
0
],
column
[
1
],
column
[
2
])
end
...
...
@@ -617,6 +617,71 @@ EOS
#
EOS
end
describe
'with_comment option'
do
mocked_columns_with_comment
=
[
[
:id
,
:integer
,
{
limit:
8
,
comment:
'ID'
}],
[
:active
,
:boolean
,
{
limit:
1
,
comment:
'Active'
}],
[
:name
,
:string
,
{
limit:
50
,
comment:
'Name'
}],
[
:notes
,
:text
,
{
limit:
55
,
comment:
'Notes'
}]
]
when_called_with
with_comment:
'yes'
,
with_columns:
mocked_columns_with_comment
,
returns:
<<-
EOS
.
strip_heredoc
# Schema Info
#
# Table name: users
#
# id(ID) :integer not null, primary key
# active(Active) :boolean not null
# name(Name) :string(50) not null
# notes(Notes) :text(55) not null
#
EOS
it
'should get schema info as RDoc'
do
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
,
comment:
'ID'
),
mock_column
(
:name
,
:string
,
limit:
50
,
comment:
'Name'
)
])
expect
(
AnnotateModels
.
get_schema_info
(
klass
,
AnnotateModels
::
PREFIX
,
format_rdoc:
true
,
with_comment:
true
)).
to
eql
(
<<-
EOS
.
strip_heredoc
)
#
#{
AnnotateModels
::
PREFIX
}
#
# Table name: users
#
# *id(ID)*:: <tt>integer, not null, primary key</tt>
# *name(Name)*:: <tt>string(50), not null</tt>
#--
#
#{
AnnotateModels
::
END_MARK
}
#++
EOS
end
it
'should get schema info as Markdown'
do
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
,
comment:
'ID'
),
mock_column
(
:name
,
:string
,
limit:
50
,
comment:
'Name'
)
])
expect
(
AnnotateModels
.
get_schema_info
(
klass
,
AnnotateModels
::
PREFIX
,
format_markdown:
true
,
with_comment:
true
)).
to
eql
(
<<-
EOS
.
strip_heredoc
)
#
#{
AnnotateModels
::
PREFIX
}
#
# Table name: `users`
#
# ### Columns
#
# Name | Type | Attributes
# ----------------- | ------------------ | ---------------------------
# **`id(ID)`** | `integer` | `not null, primary key`
# **`name(Name)`** | `string(50)` | `not null`
#
EOS
end
end
end
describe
'#get_model_class'
do
...
...
This diff is collapsed.
Click to expand it.
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