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
53941460
Commit
53941460
authored
Jun 02, 2017
by
Daniel Hanke
Committed by
Cuong Tran
Jun 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optional fk-truncation and allow rake 12 (#458)
parent
8910f041
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
2 deletions
+40
-2
annotate.gemspec
annotate.gemspec
+1
-1
annotate_models.rb
lib/annotate/annotate_models.rb
+1
-1
auto_annotate_models.rake
lib/generators/annotate/templates/auto_annotate_models.rake
+1
-0
annotate_models.rake
lib/tasks/annotate_models.rake
+1
-0
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+36
-0
No files found.
annotate.gemspec
View file @
53941460
...
...
@@ -43,6 +43,6 @@ Gem::Specification.new do |s|
s
.
summary
=
'Annotates Rails Models, routes, fixtures, and others based on the database schema.'
s
.
specification_version
=
4
if
s
.
respond_to?
:specification_version
s
.
add_runtime_dependency
(
%q<rake>
,
[
'>= 10.4'
])
s
.
add_runtime_dependency
(
%q<rake>
,
[
'>= 10.4'
,
'< 13.0'
])
s
.
add_runtime_dependency
(
%q<activerecord>
,
[
'>= 3.2'
,
'< 6.0'
])
end
lib/annotate/annotate_models.rb
View file @
53941460
...
...
@@ -374,7 +374,7 @@ module AnnotateModels
foreign_keys
=
klass
.
connection
.
foreign_keys
(
klass
.
table_name
)
return
''
if
foreign_keys
.
empty?
format_name
=
->
(
fk
)
{
fk
.
name
.
gsub
(
/(?<=^fk_rails_)[0-9a-f]{10}$/
,
'...'
)
}
format_name
=
->
(
fk
)
{
options
[
:show_complete_foreign_keys
]
?
fk
.
name
:
fk
.
name
.
gsub
(
/(?<=^fk_rails_)[0-9a-f]{10}$/
,
'...'
)
}
max_size
=
foreign_keys
.
map
(
&
format_name
).
map
(
&
:size
).
max
+
1
foreign_keys
.
sort_by
{
|
fk
|
[
format_name
.
call
(
fk
),
fk
.
column
]}.
each
do
|
fk
|
...
...
lib/generators/annotate/templates/auto_annotate_models.rake
View file @
53941460
...
...
@@ -15,6 +15,7 @@ if Rails.env.development?
'position_in_factory'
=>
'before'
,
'position_in_serializer'
=>
'before'
,
'show_foreign_keys'
=>
'true'
,
'show_complete_foreign_keys'
=>
'false'
,
'show_indexes'
=>
'true'
,
'simple_indexes'
=>
'false'
,
'model_dir'
=>
'app/models'
,
...
...
lib/tasks/annotate_models.rake
View file @
53941460
...
...
@@ -18,6 +18,7 @@ task annotate_models: :environment do
options
[
:position_in_test
]
=
Annotate
.
fallback
(
ENV
[
'position_in_test'
],
ENV
[
'position'
])
options
[
:position_in_serializer
]
=
Annotate
.
fallback
(
ENV
[
'position_in_serializer'
],
ENV
[
'position'
])
options
[
:show_foreign_keys
]
=
Annotate
.
true?
(
ENV
[
'show_foreign_keys'
])
options
[
:show_complete_foreign_keys
]
=
Annotate
.
true?
(
ENV
[
'show_complete_foreign_keys'
])
options
[
:show_indexes
]
=
Annotate
.
true?
(
ENV
[
'show_indexes'
])
options
[
:simple_indexes
]
=
Annotate
.
true?
(
ENV
[
'simple_indexes'
])
options
[
:model_dir
]
=
ENV
[
'model_dir'
]
?
ENV
[
'model_dir'
].
split
(
','
)
:
[
'app/models'
]
...
...
spec/annotate/annotate_models_spec.rb
View file @
53941460
...
...
@@ -229,6 +229,42 @@ EOS
EOS
end
it
'should get complete foreign key info'
do
klass
=
mock_class
(
:users
,
:id
,
[
mock_column
(
:id
,
:integer
),
mock_column
(
:foreign_thing_id
,
:integer
)
],
[],
[
mock_foreign_key
(
'fk_rails_cf2568e89e'
,
'foreign_thing_id'
,
'foreign_things'
),
mock_foreign_key
(
'custom_fk_name'
,
'other_thing_id'
,
'other_things'
),
mock_foreign_key
(
'fk_rails_a70234b26c'
,
'third_thing_id'
,
'third_things'
)
])
expect
(
AnnotateModels
.
get_schema_info
(
klass
,
'Schema Info'
,
show_foreign_keys:
true
,
show_complete_foreign_keys:
true
)).
to
eql
(
<<-
EOS
)
# Schema Info
#
# Table name: users
#
# id :integer not null, primary key
# foreign_thing_id :integer not null
#
# Foreign Keys
#
# custom_fk_name (other_thing_id => other_things.id)
# fk_rails_a70234b26c (third_thing_id => third_things.id)
# fk_rails_cf2568e89e (foreign_thing_id => foreign_things.id)
#
EOS
end
it
'should get foreign key info if on_delete/on_update options present'
do
klass
=
mock_class
(
:users
,
:id
,
...
...
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