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
441fc007
Commit
441fc007
authored
Jul 29, 2016
by
Cuong Tran
Committed by
GitHub
Jul 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `unsigned` support for numeric data types (#393)
parent
593273e4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
10 deletions
+43
-10
annotate_models.rb
lib/annotate/annotate_models.rb
+19
-10
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+24
-0
No files found.
lib/annotate/annotate_models.rb
View file @
441fc007
...
...
@@ -187,15 +187,7 @@ module AnnotateModels
# the type (and length), and any optional attributes
def
get_schema_info
(
klass
,
header
,
options
=
{})
info
=
"#
#{
header
}
\n
"
info
<<
"#
\n
"
if
options
[
:format_markdown
]
info
<<
"# Table name: `
#{
klass
.
table_name
}
`
\n
"
info
<<
"#
\n
"
info
<<
"# ### Columns
\n
"
else
info
<<
"# Table name:
#{
klass
.
table_name
}
\n
"
end
info
<<
"#
\n
"
info
<<
get_schema_header_text
(
klass
,
options
)
max_size
=
klass
.
column_names
.
map
(
&
:size
).
max
||
0
max_size
+=
options
[
:format_rdoc
]
?
5
:
1
...
...
@@ -220,9 +212,9 @@ module AnnotateModels
cols
=
classified_sort
(
cols
)
if
options
[
:classified_sort
]
cols
.
each
do
|
col
|
col_type
=
(
col
.
type
||
col
.
sql_type
).
to_s
attrs
=
[]
attrs
<<
"default(
#{
schema_default
(
klass
,
col
)
}
)"
unless
col
.
default
.
nil?
||
hide_default?
(
col_type
,
options
)
attrs
<<
'unsigned'
if
col
.
respond_to?
(
:unsigned?
)
&&
col
.
unsigned?
attrs
<<
'not null'
unless
col
.
null
attrs
<<
'primary key'
if
klass
.
primary_key
&&
(
klass
.
primary_key
.
is_a?
(
Array
)
?
klass
.
primary_key
.
collect
(
&
:
to_sym
).
include?
(
col
.
name
.
to_sym
)
:
col
.
name
.
to_sym
==
klass
.
primary_key
.
to_sym
)
...
...
@@ -280,6 +272,23 @@ module AnnotateModels
info
<<
get_foreign_key_info
(
klass
,
options
)
end
info
<<
get_schema_footer_text
(
klass
,
options
)
end
def
get_schema_header_text
(
klass
,
options
=
{})
info
=
"#
\n
"
if
options
[
:format_markdown
]
info
<<
"# Table name: `
#{
klass
.
table_name
}
`
\n
"
info
<<
"#
\n
"
info
<<
"# ### Columns
\n
"
else
info
<<
"# Table name:
#{
klass
.
table_name
}
\n
"
end
info
<<
"#
\n
"
end
def
get_schema_footer_text
(
_klass
,
options
=
{})
info
=
""
if
options
[
:format_rdoc
]
info
<<
"#--
\n
"
info
<<
"#
#{
END_MARK
}
\n
"
...
...
spec/annotate/annotate_models_spec.rb
View file @
441fc007
...
...
@@ -118,6 +118,7 @@ EOS
#
EOS
end
it
"should get schema info with enum type "
do
klass
=
mock_class
(
:users
,
nil
,
[
mock_column
(
:id
,
:integer
),
...
...
@@ -135,6 +136,29 @@ EOS
EOS
end
it
"should get schema info with unsigned"
do
klass
=
mock_class
(
:users
,
nil
,
[
mock_column
(
:id
,
:integer
),
mock_column
(
:integer
,
:integer
,
:unsigned?
=>
true
),
mock_column
(
:bigint
,
:bigint
,
:unsigned?
=>
true
),
mock_column
(
:float
,
:float
,
:unsigned?
=>
true
),
mock_column
(
:decimal
,
:decimal
,
:unsigned?
=>
true
,
:precision
=>
10
,
:scale
=>
2
),
])
expect
(
AnnotateModels
.
get_schema_info
(
klass
,
"Schema Info"
)).
to
eql
(
<<-
EOS
)
# Schema Info
#
# Table name: users
#
# id :integer not null
# integer :integer unsigned, not null
# bigint :bigint unsigned, not null
# float :float unsigned, not null
# decimal :decimal(10, 2) unsigned, not null
#
EOS
end
it
"should get schema info for integer and boolean with default"
do
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
),
...
...
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