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
f96592dc
Commit
f96592dc
authored
Feb 29, 2012
by
Jon Frisby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wider type column output, play nice with Rake CLI.
parent
809a29f9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
18 deletions
+24
-18
History.txt
History.txt
+4
-0
annotate_models.rb
lib/annotate/annotate_models.rb
+14
-10
auto_annotate_models.rake
...ators/annotate_models/templates/auto_annotate_models.rake
+0
-1
annotate_models.rake
lib/tasks/annotate_models.rake
+3
-2
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+3
-4
todo.txt
todo.txt
+0
-1
No files found.
History.txt
View file @
f96592dc
== HEAD
== HEAD
* Widen type column so we can handle longtexts with chopping things off.
* Skip trying to get list of models from commandline when running via Rake (was
preventing the use of multiple rake tasks in one command if one of them was
db:migrate).
* Add ability to skip annotations for a model by adding
* Add ability to skip annotations for a model by adding
'# -*- SkipSchemaAnnotations' anywhere in the file.
'# -*- SkipSchemaAnnotations' anywhere in the file.
* Don't show column limits for integer and boolean types.
* Don't show column limits for integer and boolean types.
...
...
lib/annotate/annotate_models.rb
View file @
f96592dc
...
@@ -61,7 +61,7 @@ module AnnotateModels
...
@@ -61,7 +61,7 @@ module AnnotateModels
info
<<
"#
\n
"
info
<<
"#
\n
"
max_size
=
klass
.
column_names
.
map
{
|
name
|
name
.
size
}.
max
||
0
max_size
=
klass
.
column_names
.
map
{
|
name
|
name
.
size
}.
max
||
0
max_size
+=
ENV
[
'format_rdoc'
]
?
5
:
1
max_size
+=
options
[
:format_rdoc
]
?
5
:
1
klass
.
columns
.
sort_by
(
&
:name
).
each
do
|
col
|
klass
.
columns
.
sort_by
(
&
:name
).
each
do
|
col
|
attrs
=
[]
attrs
=
[]
attrs
<<
"default(
#{
quote
(
col
.
default
)
}
)"
unless
col
.
default
.
nil?
attrs
<<
"default(
#{
quote
(
col
.
default
)
}
)"
unless
col
.
default
.
nil?
...
@@ -95,10 +95,10 @@ module AnnotateModels
...
@@ -95,10 +95,10 @@ module AnnotateModels
end
end
end
end
if
ENV
[
'format_rdoc'
]
if
options
[
:format_rdoc
]
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s<tt>%s</tt>"
,
"*
#{
col
.
name
}
*::"
,
attrs
.
unshift
(
col_type
).
join
(
", "
)).
rstrip
+
"
\n
"
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s<tt>%s</tt>"
,
"*
#{
col
.
name
}
*::"
,
attrs
.
unshift
(
col_type
).
join
(
", "
)).
rstrip
+
"
\n
"
else
else
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s:%-1
5.15
s %s"
,
col
.
name
,
col_type
,
attrs
.
join
(
", "
)).
rstrip
+
"
\n
"
info
<<
sprintf
(
"# %-
#{
max_size
}
.
#{
max_size
}
s:%-1
6.16
s %s"
,
col
.
name
,
col_type
,
attrs
.
join
(
", "
)).
rstrip
+
"
\n
"
end
end
end
end
...
@@ -106,7 +106,7 @@ module AnnotateModels
...
@@ -106,7 +106,7 @@ module AnnotateModels
info
<<
get_index_info
(
klass
)
info
<<
get_index_info
(
klass
)
end
end
if
ENV
[
'format_rdoc'
]
if
options
[
:format_rdoc
]
info
<<
"#--
\n
"
info
<<
"#--
\n
"
info
<<
"#
#{
END_MARK
}
\n
"
info
<<
"#
#{
END_MARK
}
\n
"
info
<<
"#++
\n\n
"
info
<<
"#++
\n\n
"
...
@@ -246,9 +246,13 @@ module AnnotateModels
...
@@ -246,9 +246,13 @@ module AnnotateModels
# the underscore or CamelCase versions of model names.
# the underscore or CamelCase versions of model names.
# Otherwise we take all the model files in the
# Otherwise we take all the model files in the
# model_dir directory.
# model_dir directory.
def
get_model_files
def
get_model_files
(
options
)
models
=
ARGV
.
dup
if
(
!
options
[
:is_rake
])
models
.
shift
models
=
ARGV
.
dup
models
.
shift
else
models
=
[]
end
models
.
reject!
{
|
m
|
m
.
match
(
/^(.*)=/
)}
models
.
reject!
{
|
m
|
m
.
match
(
/^(.*)=/
)}
if
models
.
empty?
if
models
.
empty?
begin
begin
...
@@ -308,10 +312,10 @@ module AnnotateModels
...
@@ -308,10 +312,10 @@ module AnnotateModels
end
end
annotated
=
[]
annotated
=
[]
get_model_files
.
each
do
|
file
|
get_model_files
(
options
)
.
each
do
|
file
|
begin
begin
klass
=
get_model_class
(
file
)
klass
=
get_model_class
(
file
)
if
klass
<
ActiveRecord
::
Base
&&
!
klass
.
abstract_class?
if
klass
&&
klass
<
ActiveRecord
::
Base
&&
!
klass
.
abstract_class?
if
annotate
(
klass
,
file
,
header
,
options
)
if
annotate
(
klass
,
file
,
header
,
options
)
annotated
<<
klass
annotated
<<
klass
end
end
...
@@ -333,7 +337,7 @@ module AnnotateModels
...
@@ -333,7 +337,7 @@ module AnnotateModels
self
.
model_dir
=
options
[
:model_dir
]
self
.
model_dir
=
options
[
:model_dir
]
end
end
deannotated
=
[]
deannotated
=
[]
get_model_files
.
each
do
|
file
|
get_model_files
(
options
)
.
each
do
|
file
|
begin
begin
klass
=
get_model_class
(
file
)
klass
=
get_model_class
(
file
)
if
klass
<
ActiveRecord
::
Base
&&
!
klass
.
abstract_class?
if
klass
<
ActiveRecord
::
Base
&&
!
klass
.
abstract_class?
...
...
lib/generators/annotate_models/templates/auto_annotate_models.rake
View file @
f96592dc
...
@@ -13,5 +13,4 @@ if(Rails.env.development?)
...
@@ -13,5 +13,4 @@ if(Rails.env.development?)
ENV
[
'exclude_fixtures'
]
=
"false"
ENV
[
'exclude_fixtures'
]
=
"false"
ENV
[
'skip_on_db_migrate'
]
=
"false"
ENV
[
'skip_on_db_migrate'
]
=
"false"
ENV
[
'format_rdoc'
]
=
"false"
ENV
[
'format_rdoc'
]
=
"false"
ENV
[
'format_bare'
]
=
"true"
end
end
lib/tasks/annotate_models.rake
View file @
f96592dc
...
@@ -5,7 +5,7 @@ task :annotate_models => :environment do
...
@@ -5,7 +5,7 @@ task :annotate_models => :environment do
true_re
=
/(true|t|yes|y|1)$/i
true_re
=
/(true|t|yes|y|1)$/i
options
=
{}
options
=
{
:is_rake
=>
true
}
options
[
:position_in_class
]
=
ENV
[
'position_in_class'
]
||
ENV
[
'position'
]
||
'before'
options
[
:position_in_class
]
=
ENV
[
'position_in_class'
]
||
ENV
[
'position'
]
||
'before'
options
[
:position_in_fixture
]
=
ENV
[
'position_in_fixture'
]
||
ENV
[
'position'
]
||
'before'
options
[
:position_in_fixture
]
=
ENV
[
'position_in_fixture'
]
||
ENV
[
'position'
]
||
'before'
options
[
:position_in_factory
]
=
ENV
[
'position_in_factory'
]
||
ENV
[
'position'
]
||
'before'
options
[
:position_in_factory
]
=
ENV
[
'position_in_factory'
]
||
ENV
[
'position'
]
||
'before'
...
@@ -16,6 +16,7 @@ task :annotate_models => :environment do
...
@@ -16,6 +16,7 @@ task :annotate_models => :environment do
options
[
:require
]
=
ENV
[
'require'
]
?
ENV
[
'require'
].
split
(
','
)
:
[]
options
[
:require
]
=
ENV
[
'require'
]
?
ENV
[
'require'
].
split
(
','
)
:
[]
options
[
:exclude_tests
]
=
ENV
[
'exclude_tests'
]
=~
true_re
options
[
:exclude_tests
]
=
ENV
[
'exclude_tests'
]
=~
true_re
options
[
:exclude_fixtures
]
=
ENV
[
'exclude_fixtures'
]
=~
true_re
options
[
:exclude_fixtures
]
=
ENV
[
'exclude_fixtures'
]
=~
true_re
options
[
:format_rdoc
]
=
ENV
[
'format_rdoc'
]
=~
true_re
AnnotateModels
.
do_annotations
(
options
)
AnnotateModels
.
do_annotations
(
options
)
end
end
...
@@ -23,7 +24,7 @@ desc "Remove schema information from model and fixture files"
...
@@ -23,7 +24,7 @@ desc "Remove schema information from model and fixture files"
task
:remove_annotation
=>
:environment
do
task
:remove_annotation
=>
:environment
do
require
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'annotate'
,
'annotate_models'
))
require
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'annotate'
,
'annotate_models'
))
require
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'annotate'
,
'active_record_patch'
))
require
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'annotate'
,
'active_record_patch'
))
options
=
{}
options
=
{
:is_rake
=>
true
}
options
[
:model_dir
]
=
ENV
[
'model_dir'
]
options
[
:model_dir
]
=
ENV
[
'model_dir'
]
AnnotateModels
.
remove_annotations
(
options
)
AnnotateModels
.
remove_annotations
(
options
)
end
end
spec/annotate/annotate_models_spec.rb
View file @
f96592dc
...
@@ -48,8 +48,8 @@ describe AnnotateModels do
...
@@ -48,8 +48,8 @@ describe AnnotateModels do
#
#
# Table name: users
# Table name: users
#
#
# id :integer not null, primary key
# id :integer
not null, primary key
# name :string(50) not null
# name :string(50)
not null
#
#
EOS
EOS
...
@@ -60,8 +60,7 @@ EOS
...
@@ -60,8 +60,7 @@ EOS
mock_column
(
:id
,
:integer
),
mock_column
(
:id
,
:integer
),
mock_column
(
:name
,
:string
,
:limit
=>
50
)
mock_column
(
:name
,
:string
,
:limit
=>
50
)
])
])
ENV
.
stub!
(
:[]
).
with
(
'format_rdoc'
).
and_return
(
true
)
AnnotateModels
.
get_schema_info
(
klass
,
AnnotateModels
::
PREFIX
,
:format_rdoc
=>
true
).
should
eql
(
<<-
EOS
)
AnnotateModels
.
get_schema_info
(
klass
,
AnnotateModels
::
PREFIX
).
should
eql
(
<<-
EOS
)
#
#{
AnnotateModels
::
PREFIX
}
#
#{
AnnotateModels
::
PREFIX
}
#
#
# Table name: users
# Table name: users
...
...
todo.txt
View file @
f96592dc
...
@@ -2,4 +2,3 @@ TODO
...
@@ -2,4 +2,3 @@ TODO
-----
-----
add "top" and "bottom" as synonyms for "before" and "after"
add "top" and "bottom" as synonyms for "before" and "after"
change 'exclude' to 'only' (double negatives are not unconfusing)
change 'exclude' to 'only' (double negatives are not unconfusing)
make format_* options go through normal channel for options
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