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
6775e4a1
Commit
6775e4a1
authored
Jul 04, 2017
by
Alexander Belozerov
Committed by
Cuong Tran
Jul 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Indexes: add WHERE and USING (#482)
parent
5803fbaa
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
2 deletions
+59
-2
annotate_models.rb
lib/annotate/annotate_models.rb
+59
-2
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+0
-0
No files found.
lib/annotate/annotate_models.rb
View file @
6775e4a1
...
@@ -65,6 +65,21 @@ module AnnotateModels
...
@@ -65,6 +65,21 @@ module AnnotateModels
# Don't show default value for these column types
# Don't show default value for these column types
NO_DEFAULT_COL_TYPES
=
%w(json jsonb hstore)
.
freeze
NO_DEFAULT_COL_TYPES
=
%w(json jsonb hstore)
.
freeze
INDEX_CLAUSES
=
{
unique:
{
default:
'UNIQUE'
,
markdown:
'_unique_'
},
where:
{
default:
'WHERE'
,
markdown:
'_where_'
},
using:
{
default:
'USING'
,
markdown:
'_using_'
}
}.
freeze
class
<<
self
class
<<
self
def
annotate_pattern
(
options
=
{})
def
annotate_pattern
(
options
=
{})
if
options
[
:wrapper_open
]
if
options
[
:wrapper_open
]
...
@@ -356,12 +371,54 @@ module AnnotateModels
...
@@ -356,12 +371,54 @@ module AnnotateModels
end
end
end
end
def
index_unique_info
(
index
,
format
=
:default
)
index
.
unique
?
"
#{
INDEX_CLAUSES
[
:unique
][
format
]
}
"
:
''
end
def
index_where_info
(
index
,
format
=
:default
)
value
=
index
.
try
(
:where
).
try
(
:to_s
)
if
value
.
blank?
''
else
"
#{
INDEX_CLAUSES
[
:where
][
format
]
}
#{
value
}
"
end
end
def
index_using_info
(
index
,
format
=
:default
)
value
=
index
.
try
(
:using
)
&&
index
.
using
.
try
(
:to_sym
)
if
!
value
.
blank?
&&
value
!=
:btree
"
#{
INDEX_CLAUSES
[
:using
][
format
]
}
#{
value
}
"
else
''
end
end
def
final_index_string_in_markdown
(
index
)
def
final_index_string_in_markdown
(
index
)
sprintf
(
"# * `%s`%s:
\n
# * **`%s`**
\n
"
,
index
.
name
,
index
.
unique
?
" (_unique_)"
:
""
,
index_columns_info
(
index
).
join
(
"`**
\n
# * **`"
))
details
=
sprintf
(
"%s%s%s"
,
index_unique_info
(
index
,
:markdown
),
index_where_info
(
index
,
:markdown
),
index_using_info
(
index
,
:markdown
)
).
strip
details
=
" (
#{
details
}
)"
unless
details
.
blank?
sprintf
(
"# * `%s`%s:
\n
# * **`%s`**
\n
"
,
index
.
name
,
details
,
index_columns_info
(
index
).
join
(
"`**
\n
# * **`"
)
)
end
end
def
final_index_string
(
index
,
max_size
)
def
final_index_string
(
index
,
max_size
)
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s %s %s"
,
index
.
name
,
"(
#{
index_columns_info
(
index
).
join
(
','
)
}
)"
,
index
.
unique
?
"UNIQUE"
:
""
).
rstrip
+
"
\n
"
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s %s%s%s%s"
,
index
.
name
,
"(
#{
index_columns_info
(
index
).
join
(
','
)
}
)"
,
index_unique_info
(
index
),
index_where_info
(
index
),
index_using_info
(
index
)
).
rstrip
+
"
\n
"
end
end
def
hide_limit?
(
col_type
,
options
)
def
hide_limit?
(
col_type
,
options
)
...
...
spec/annotate/annotate_models_spec.rb
View file @
6775e4a1
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