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
baa00178
Commit
baa00178
authored
Mar 28, 2009
by
Bob Potter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add options for show indexes in annotations
parent
4aee03d3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
2 deletions
+21
-2
annotate
bin/annotate
+1
-0
annotate_models.rb
lib/annotate/annotate_models.rb
+19
-2
annotate.rake
lib/tasks/annotate.rake
+0
-0
annotate_models.rake
lib/tasks/annotate_models.rake
+1
-0
No files found.
bin/annotate
View file @
baa00178
...
...
@@ -12,6 +12,7 @@ OptionParser.new do |opts|
opts
.
on
(
'-r'
,
'--routes'
)
{
task
=
:annotate_routes
}
opts
.
on
(
'-v'
,
'--version'
)
{
puts
"Annotate v
#{
Annotate
::
VERSION
}
"
;
exit
}
opts
.
on
(
'-m'
,
'--show-migration'
)
{
ENV
[
'include_version'
]
=
"yes"
}
opts
.
on
(
'-i'
,
'--show-indexes'
)
{
ENV
[
'show_indexes'
]
=
"yes"
}
end
.
parse!
begin
...
...
lib/annotate/annotate_models.rb
View file @
baa00178
...
...
@@ -32,7 +32,7 @@ module AnnotateModels
# to create a comment block containing a line for
# each column. The line contains the column name,
# the type (and length), and any optional attributes
def
get_schema_info
(
klass
,
header
)
def
get_schema_info
(
klass
,
header
,
options
=
{}
)
info
=
"#
#{
header
}
\n
#
\n
"
info
<<
"# Table name:
#{
klass
.
table_name
}
\n
#
\n
"
...
...
@@ -59,9 +59,26 @@ module AnnotateModels
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s:%-15.15s %s"
,
col
.
name
,
col_type
,
attrs
.
join
(
", "
)).
rstrip
+
"
\n
"
end
if
options
[
:show_indexes
]
info
<<
get_index_info
(
klass
)
end
info
<<
"#
\n\n
"
end
def
get_index_info
(
klass
)
index_info
=
"#
\n
# Indexes
\n
#
\n
"
indexes
=
klass
.
connection
.
indexes
(
klass
.
table_name
)
return
""
if
indexes
.
empty?
max_size
=
indexes
.
collect
{
|
index
|
index
.
name
.
size
}.
max
+
1
indexes
.
each
do
|
index
|
index_info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s %s %s"
,
index
.
name
,
"(
#{
index
.
columns
.
join
(
","
)
}
)"
,
index
.
unique
?
"UNIQUE"
:
""
).
rstrip
+
"
\n
"
end
return
index_info
end
# Add a schema block to a file. If the file already contains
# a schema info block (a comment starting with "== Schema Information"), check if it
# matches the block that is already there. If so, leave it be. If not, remove the old
...
...
@@ -116,7 +133,7 @@ module AnnotateModels
# files were modified.
def
annotate
(
klass
,
file
,
header
,
options
=
{})
info
=
get_schema_info
(
klass
,
header
)
info
=
get_schema_info
(
klass
,
header
,
options
)
annotated
=
false
model_name
=
klass
.
name
.
underscore
model_file_name
=
File
.
join
(
MODEL_DIR
,
file
)
...
...
lib/tasks/annotate.rake
View file @
baa00178
lib/tasks/annotate_models.rake
View file @
baa00178
...
...
@@ -4,6 +4,7 @@ task :annotate_models => :environment do
options
=
{}
options
[
:position_in_class
]
=
ENV
[
'position_in_class'
]
||
ENV
[
'position'
]
||
:before
options
[
:position_in_fixture
]
=
ENV
[
'position_in_fixture'
]
||
ENV
[
'position'
]
||
:before
options
[
:show_indexes
]
=
ENV
[
'show_indexes'
]
AnnotateModels
.
do_annotations
(
options
)
end
...
...
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