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
ffceca9b
Commit
ffceca9b
authored
Aug 21, 2009
by
Marcos Piccinini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add simple_indexes option
parent
513b837f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
39 additions
and
22 deletions
+39
-22
VERSION
VERSION
+1
-0
VERSION.yml
VERSION.yml
+0
-4
annotate.gemspec
annotate.gemspec
+7
-4
annotate
bin/annotate
+15
-11
annotate_models.rb
lib/annotate/annotate_models.rb
+11
-0
annotate_models.rake
lib/tasks/annotate_models.rake
+2
-1
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+3
-2
No files found.
VERSION
0 → 100644
View file @
ffceca9b
2.3.2
VERSION.yml
deleted
100644 → 0
View file @
513b837f
---
:major
:
2
:minor
:
3
:patch
:
1
annotate.gemspec
View file @
ffceca9b
# Generated by jeweler
# DO NOT EDIT THIS FILE
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
# -*- encoding: utf-8 -*-
Gem
::
Specification
.
new
do
|
s
|
s
.
name
=
%q{annotate}
s
.
version
=
"2.3.
1
"
s
.
version
=
"2.3.
2
"
s
.
required_rubygems_version
=
Gem
::
Requirement
.
new
(
">= 0"
)
if
s
.
respond_to?
:required_rubygems_version
=
s
.
authors
=
[
"Cuong Tran"
,
"Marcos Piccinini"
]
s
.
date
=
%q{2009-0
7-02
}
s
.
date
=
%q{2009-0
8-21
}
s
.
default_executable
=
%q{annotate}
s
.
email
=
%q{x@nofxx.com}
s
.
executables
=
[
"annotate"
]
...
...
@@ -18,7 +21,7 @@ Gem::Specification.new do |s|
"History.txt"
,
"README.rdoc"
,
"Rakefile"
,
"VERSION
.yml
"
,
"VERSION"
,
"annotate.gemspec"
,
"bin/annotate"
,
"lib/annotate.rb"
,
...
...
@@ -35,7 +38,7 @@ Gem::Specification.new do |s|
s
.
homepage
=
%q{http://github.com/nofxx/annotate}
s
.
rdoc_options
=
[
"--charset=UTF-8"
]
s
.
require_paths
=
[
"lib"
]
s
.
rubygems_version
=
%q{1.3.
4
}
s
.
rubygems_version
=
%q{1.3.
5
}
s
.
summary
=
%q{Annotates Rails Models, routes, and others}
s
.
test_files
=
[
"spec/annotate/annotate_models_spec.rb"
,
...
...
bin/annotate
View file @
ffceca9b
...
...
@@ -7,31 +7,35 @@ task = :annotate_models
OptionParser
.
new
do
|
opts
|
opts
.
banner
=
"Usage: annotate [options]"
opts
.
on
(
'-d'
,
'--delete'
,
opts
.
on
(
'-d'
,
'--delete'
,
"Remove annotations from all model files"
)
do
task
=
:remove_annotation
end
opts
.
on
(
'-p'
,
'--position [before|after]'
,
[
'before'
,
'after'
],
"Place the annotations at the top (before) or the bottom (after) of the model file"
)
do
|
p
|
opts
.
on
(
'-p'
,
'--position [before|after]'
,
[
'before'
,
'after'
],
"Place the annotations at the top (before) or the bottom (after) of the model file"
)
do
|
p
|
ENV
[
'position'
]
=
p
end
opts
.
on
(
'-r'
,
'--routes'
,
opts
.
on
(
'-r'
,
'--routes'
,
"Annotate routes.rb with the output of 'rake routes'"
)
do
task
=
:annotate_routes
end
opts
.
on
(
'-v'
,
'--version'
,
"Show the current version of this gem"
)
do
puts
"Annotate v
#{
Annotate
::
VERSION
}
"
;
exit
opts
.
on
(
'-v'
,
'--version'
,
"Show the current version of this gem"
)
do
puts
"Annotate v
#{
Annotate
::
VERSION
}
"
;
exit
end
opts
.
on
(
'-m'
,
'--show-migration'
,
opts
.
on
(
'-m'
,
'--show-migration'
,
"Include the migration version number in the annotation"
)
do
ENV
[
'include_version'
]
=
"yes"
end
opts
.
on
(
'-i'
,
'--show-indexes'
,
"List the table's database indexes in the annotation"
)
do
opts
.
on
(
'-i'
,
'--show-indexes'
,
"List the table's database indexes in the annotation"
)
do
ENV
[
'show_indexes'
]
=
"yes"
end
opts
.
on
(
'--model-dir dir'
,
opts
.
on
(
'-s'
,
'--simple-indexes'
,
"Concat the column's related indexes in the annotation"
)
do
ENV
[
'simple_indexes'
]
=
"yes"
end
opts
.
on
(
'--model-dir dir'
,
"Annotate model files stored in dir rather than app/models"
)
do
|
dir
|
ENV
[
'model_dir'
]
=
dir
end
...
...
lib/annotate/annotate_models.rb
View file @
ffceca9b
...
...
@@ -64,6 +64,17 @@ module AnnotateModels
attrs
<<
"
#{
col
.
geometry_type
}
,
#{
col
.
srid
}
"
end
# Check if the column has indices and print "indexed" if true
# If the indice include another colum, print it too.
if
options
[
:simple_indexes
]
# Check out if this column is indexed
indices
=
klass
.
connection
.
indexes
(
klass
.
table_name
)
if
indices
=
indices
.
select
{
|
ind
|
ind
.
columns
.
include?
col
.
name
}
indices
.
each
do
|
ind
|
ind
=
ind
.
columns
.
reject!
{
|
i
|
i
==
col
.
name
}
attrs
<<
(
ind
.
length
==
0
?
"indexed"
:
"indexed => [
#{
ind
.
join
(
", "
)
}
]"
)
end
end
end
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s:%-15.15s %s"
,
col
.
name
,
col_type
,
attrs
.
join
(
", "
)).
rstrip
+
"
\n
"
end
...
...
lib/tasks/annotate_models.rake
View file @
ffceca9b
...
...
@@ -5,9 +5,10 @@ task :annotate_models => :environment do
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'
]
options
[
:simple_indexes
]
=
ENV
[
'simple_indexes'
]
options
[
:model_dir
]
=
ENV
[
'model_dir'
]
options
[
:include_version
]
=
ENV
[
'include_version'
]
options
[
:require
]
=
ENV
[
'require'
].
split
(
','
)
options
[
:require
]
=
ENV
[
'require'
].
split
(
','
)
rescue
[]
AnnotateModels
.
do_annotations
(
options
)
end
...
...
spec/annotate/annotate_models_spec.rb
View file @
ffceca9b
...
...
@@ -23,6 +23,7 @@ describe AnnotateModels do
it
"should get schema info"
do
AnnotateModels
.
get_schema_info
(
mock_klass
(
:connection
=>
mock
(
"Conn"
,
:indexes
=>
[]),
:table_name
=>
"users"
,
:primary_key
=>
"id"
,
:column_names
=>
[
"id"
,
"login"
],
...
...
@@ -41,7 +42,7 @@ describe AnnotateModels do
EOS
end
describe
"#get_model_class"
do
module
::
ActiveRecord
class
Base
...
...
@@ -61,7 +62,7 @@ EOS
AnnotateModels
.
model_dir
=
@dir
create
(
'foo.rb'
,
<<-
EOS
)
class Foo < ActiveRecord::Base
end
end
EOS
create
(
'foo_with_macro.rb'
,
<<-
EOS
)
class FooWithMacro < ActiveRecord::Base
...
...
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