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
d260a199
Commit
d260a199
authored
Mar 03, 2015
by
Cuong Tran
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #209 from vasilakisfil/classified_sort
Add option for classified annotation (id first, timestamps/assotiactions last)
parents
6464fc08
34c963e5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
1 deletion
+33
-1
annotate
bin/annotate
+5
-0
annotate.rb
lib/annotate.rb
+3
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+24
-0
annotate_models.rake
lib/tasks/annotate_models.rake
+1
-0
No files found.
bin/annotate
View file @
d260a199
...
...
@@ -134,6 +134,11 @@ OptionParser.new do |opts|
ENV
[
'sort'
]
=
"yes"
end
opts
.
on
(
'--classified-sort'
,
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns"
)
do
|
dir
|
ENV
[
'classified_sort'
]
=
"yes"
end
opts
.
on
(
'-R'
,
'--require path'
,
"Additional file to require before loading models, may be used multiple times"
)
do
|
path
|
if
!
ENV
[
'require'
].
blank?
...
...
lib/annotate.rb
View file @
d260a199
...
...
@@ -6,9 +6,11 @@ require 'annotate/annotate_routes'
begin
# ActiveSupport 3.x...
require
'active_support/hash_with_indifferent_access'
require
'active_support/core_ext/object/blank'
rescue
Exception
=>
e
# ActiveSupport 2.x...
require
'active_support/core_ext/hash/indifferent_access'
require
'active_support/core_ext/blank'
end
module
Annotate
...
...
@@ -24,7 +26,7 @@ module Annotate
:show_indexes
,
:simple_indexes
,
:include_version
,
:exclude_tests
,
:exclude_fixtures
,
:exclude_factories
,
:ignore_model_sub_dir
,
:format_bare
,
:format_rdoc
,
:format_markdown
,
:sort
,
:force
,
:trace
,
:timestamp
,
:exclude_serializers
:timestamp
,
:exclude_serializers
,
:classified_sort
]
OTHER_OPTIONS
=
[
:ignore_columns
...
...
lib/annotate/annotate_models.rb
View file @
d260a199
...
...
@@ -125,7 +125,9 @@ module AnnotateModels
if
options
[
:ignore_columns
]
cols
.
reject!
{
|
col
|
col
.
name
.
match
(
/
#{
options
[
:ignore_columns
]
}
/
)
}
end
cols
=
cols
.
sort_by
(
&
:name
)
if
(
options
[
:sort
])
cols
=
classified_sort
(
cols
)
if
(
options
[
:classified_sort
])
cols
.
each
do
|
col
|
attrs
=
[]
attrs
<<
"default(
#{
quote
(
col
.
default
)
}
)"
unless
col
.
default
.
nil?
...
...
@@ -492,5 +494,27 @@ module AnnotateModels
gsub
(
'%MODEL_NAME%'
,
model_name
).
gsub
(
'%TABLE_NAME%'
,
table_name
||
model_name
.
pluralize
)
end
def
classified_sort
(
cols
)
rest_cols
=
[]
timestamps
=
[]
associations
=
[]
id
=
nil
cols
=
cols
.
each
do
|
c
|
if
c
.
name
.
eql?
(
"id"
)
id
=
c
elsif
(
c
.
name
.
eql?
(
"created_at"
)
||
c
.
name
.
eql?
(
"updated_at"
))
timestamps
<<
c
elsif
c
.
name
[
-
3
,
3
].
eql?
(
"_id"
)
associations
<<
c
else
rest_cols
<<
c
end
end
[
rest_cols
,
timestamps
,
associations
].
each
{
|
a
|
a
.
sort_by!
(
&
:name
)
}
return
([
id
]
<<
rest_cols
<<
timestamps
<<
associations
).
flatten
end
end
end
lib/tasks/annotate_models.rake
View file @
d260a199
...
...
@@ -30,6 +30,7 @@ task :annotate_models => :environment do
options
[
:format_markdown
]
=
Annotate
.
true?
(
ENV
[
'format_markdown'
])
options
[
:sort
]
=
Annotate
.
true?
(
ENV
[
'sort'
])
options
[
:force
]
=
Annotate
.
true?
(
ENV
[
'force'
])
options
[
:classified_sort
]
=
Annotate
.
true?
(
ENV
[
'classified_sort'
])
options
[
:trace
]
=
Annotate
.
true?
(
ENV
[
'trace'
])
options
[
:wrapper_open
]
=
Annotate
.
fallback
(
ENV
[
'wrapper_open'
],
ENV
[
'wrapper'
])
options
[
:wrapper_close
]
=
Annotate
.
fallback
(
ENV
[
'wrapper_close'
],
ENV
[
'wrapper'
])
...
...
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