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
6523dd7d
Commit
6523dd7d
authored
Dec 29, 2015
by
cuong.tran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide :hide_limit_column_types option to skip column size, #278
parent
513ce35b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
5 deletions
+80
-5
annotate
bin/annotate
+4
-0
annotate.rb
lib/annotate.rb
+2
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+12
-1
auto_annotate_models.rake
lib/generators/annotate/templates/auto_annotate_models.rake
+1
-0
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+61
-3
No files found.
bin/annotate
View file @
6523dd7d
...
...
@@ -178,6 +178,10 @@ OptionParser.new do |opts|
ENV
[
'ignore_columns'
]
=
regex
end
opts
.
on
(
'--hide-limit-column-types VALUES'
,
"don't show limit for given column types, separated by comas (i.e., `integer,boolean,text`)"
)
do
|
values
|
ENV
[
'hide_limit_column_types'
]
=
"
#{
values
}
"
end
end
.
parse!
options
=
Annotate
.
setup_options
({
:is_rake
=>
ENV
[
'is_rake'
]
&&
!
ENV
[
'is_rake'
].
empty?
})
...
...
lib/annotate.rb
View file @
6523dd7d
...
...
@@ -30,7 +30,8 @@ module Annotate
:exclude_scaffolds
,
:exclude_controllers
,
:exclude_helpers
]
OTHER_OPTIONS
=
[
:ignore_columns
,
:skip_on_db_migrate
,
:wrapper_open
,
:wrapper_close
,
:wrapper
,
:routes
:ignore_columns
,
:skip_on_db_migrate
,
:wrapper_open
,
:wrapper_close
,
:wrapper
,
:routes
,
:hide_limit_column_types
,
]
PATH_OPTIONS
=
[
:require
,
:model_dir
,
:root_dir
...
...
lib/annotate/annotate_models.rb
View file @
6523dd7d
...
...
@@ -202,7 +202,7 @@ module AnnotateModels
if
col
.
limit
.
is_a?
Array
attrs
<<
"(
#{
col
.
limit
.
join
(
', '
)
}
)"
else
col_type
<<
"(
#{
col
.
limit
}
)"
unless
NO_LIMIT_COL_TYPES
.
include?
(
col_type
)
col_type
<<
"(
#{
col
.
limit
}
)"
unless
hide_limit?
(
col_type
,
options
)
end
end
end
...
...
@@ -281,6 +281,17 @@ module AnnotateModels
return
index_info
end
def
hide_limit?
(
col_type
,
options
)
excludes
=
if
options
[
:hide_limit_column_types
].
blank?
NO_LIMIT_COL_TYPES
else
options
[
:hide_limit_column_types
].
split
(
','
)
end
excludes
.
include?
(
col_type
)
end
def
get_foreign_key_info
(
klass
,
options
=
{})
if
(
options
[
:format_markdown
])
fk_info
=
"#
\n
# ### Foreign Keys
\n
#
\n
"
...
...
lib/generators/annotate/templates/auto_annotate_models.rake
View file @
6523dd7d
...
...
@@ -29,6 +29,7 @@ if Rails.env.development?
'exclude_helpers'
=>
'false'
,
'ignore_model_sub_dir'
=>
'false'
,
'ignore_columns'
=>
nil
,
'hide_limit_column_types'
=>
'<%= AnnotateModels::NO_LIMIT_COL_TYPES.join('
,
') %>'
,
'skip_on_db_migrate'
=>
'false'
,
'format_bare'
=>
'true'
,
'format_rdoc'
=>
'false'
,
...
...
spec/annotate/annotate_models_spec.rb
View file @
6523dd7d
...
...
@@ -2,6 +2,7 @@
require
File
.
dirname
(
__FILE__
)
+
'/../spec_helper.rb'
require
'annotate/annotate_models'
require
'annotate/active_record_patch'
require
'active_support/core_ext/string'
describe
AnnotateModels
do
def
mock_foreign_key
(
name
,
from_column
,
to_table
,
to_column
=
'id'
)
...
...
@@ -60,10 +61,11 @@ describe AnnotateModels do
it
{
expect
(
AnnotateModels
.
quote
(
BigDecimal
.
new
(
"1.2"
))).
to
eql
(
"1.2"
)
}
it
{
expect
(
AnnotateModels
.
quote
([
BigDecimal
.
new
(
"1.2"
)])).
to
eql
([
"1.2"
])
}
it
"should get schema info"
do
it
"should get schema info
with default options
"
do
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
),
mock_column
(
:name
,
:string
,
:limit
=>
50
)
mock_column
(
:id
,
:integer
,
:limit
=>
8
),
mock_column
(
:name
,
:string
,
:limit
=>
50
),
mock_column
(
:notes
,
:text
,
:limit
=>
55
),
])
expect
(
AnnotateModels
.
get_schema_info
(
klass
,
"Schema Info"
)).
to
eql
(
<<-
EOS
)
...
...
@@ -73,6 +75,7 @@ describe AnnotateModels do
#
# id :integer not null, primary key
# name :string(50) not null
# notes :text(55) not null
#
EOS
end
...
...
@@ -192,6 +195,61 @@ EOS
EOS
end
describe
"#get_schema_info with custom options"
do
def
self
.
when_called_with
(
options
=
{})
expected
=
options
.
delete
(
:returns
)
it
"should work with options =
#{
options
}
"
do
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
,
:limit
=>
8
),
mock_column
(
:active
,
:boolean
,
:limit
=>
1
),
mock_column
(
:name
,
:string
,
:limit
=>
50
),
mock_column
(
:notes
,
:text
,
:limit
=>
55
),
])
schema_info
=
AnnotateModels
.
get_schema_info
(
klass
,
"Schema Info"
,
options
)
expect
(
schema_info
).
to
eql
(
expected
)
end
end
when_called_with
hide_limit_column_types:
''
,
returns:
<<-
EOS
.
strip_heredoc
# Schema Info
#
# Table name: users
#
# id :integer not null, primary key
# active :boolean not null
# name :string(50) not null
# notes :text(55) not null
#
EOS
when_called_with
hide_limit_column_types:
'integer,boolean'
,
returns:
<<-
EOS
.
strip_heredoc
# Schema Info
#
# Table name: users
#
# id :integer not null, primary key
# active :boolean not null
# name :string(50) not null
# notes :text(55) not null
#
EOS
when_called_with
hide_limit_column_types:
'integer,boolean,string,text'
,
returns:
<<-
EOS
.
strip_heredoc
# Schema Info
#
# Table name: users
#
# id :integer not null, primary key
# active :boolean not null
# name :string not null
# notes :text not null
#
EOS
end
describe
"#get_model_class"
do
require
"tmpdir"
...
...
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