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
8056ecf0
Commit
8056ecf0
authored
Feb 26, 2014
by
Cuong Tran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the conversion from file path to class name which should fix #125 and #141
parent
2b34d608
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
annotate_models.rb
lib/annotate/annotate_models.rb
+5
-0
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+32
-0
No files found.
lib/annotate/annotate_models.rb
View file @
8056ecf0
...
@@ -377,6 +377,10 @@ module AnnotateModels
...
@@ -377,6 +377,10 @@ module AnnotateModels
# Retrieve loaded model class by path to the file where it's supposed to be defined.
# Retrieve loaded model class by path to the file where it's supposed to be defined.
def
get_loaded_model
(
model_path
)
def
get_loaded_model
(
model_path
)
begin
ActiveSupport
::
Inflector
.
constantize
(
ActiveSupport
::
Inflector
.
camelize
(
model_path
))
rescue
# Revert to the old way but it is not really robust
ObjectSpace
.
each_object
(
::
Class
).
ObjectSpace
.
each_object
(
::
Class
).
select
do
|
c
|
select
do
|
c
|
Class
===
c
and
# note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
Class
===
c
and
# note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
...
@@ -385,6 +389,7 @@ module AnnotateModels
...
@@ -385,6 +389,7 @@ module AnnotateModels
end
.
end
.
detect
{
|
c
|
ActiveSupport
::
Inflector
.
underscore
(
c
)
==
model_path
}
detect
{
|
c
|
ActiveSupport
::
Inflector
.
underscore
(
c
)
==
model_path
}
end
end
end
# We're passed a name of things that might be
# We're passed a name of things that might be
# ActiveRecord models. If we can find the class, and
# ActiveRecord models. If we can find the class, and
...
...
spec/annotate/annotate_models_spec.rb
View file @
8056ecf0
...
@@ -182,6 +182,38 @@ EOS
...
@@ -182,6 +182,38 @@ EOS
check_class_name
'bar/foo_inside_bar.rb'
,
'Bar::FooInsideBar'
check_class_name
'bar/foo_inside_bar.rb'
,
'Bar::FooInsideBar'
end
end
it
"should find AR model when duplicated by a nested model"
do
create
'foo.rb'
,
<<-
EOS
class Foo < ActiveRecord::Base
end
EOS
create
'bar/foo.rb'
,
<<-
EOS
class Bar::Foo
end
EOS
check_class_name
'bar/foo.rb'
,
'Bar::Foo'
check_class_name
'foo.rb'
,
'Foo'
end
it
"should find AR model nested inside a class"
do
create
'voucher.rb'
,
<<-
EOS
class Voucher < ActiveRecord::Base
end
EOS
create
'voucher/foo.rb'
,
<<-
EOS
class Voucher
class Foo
end
end
EOS
check_class_name
'voucher.rb'
,
'Voucher'
check_class_name
'voucher/foo.rb'
,
'Voucher::Foo'
end
it
"should not care about unknown macros"
do
it
"should not care about unknown macros"
do
create
'foo_with_macro.rb'
,
<<-
EOS
create
'foo_with_macro.rb'
,
<<-
EOS
class FooWithMacro < ActiveRecord::Base
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