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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
7 deletions
+44
-7
annotate_models.rb
lib/annotate/annotate_models.rb
+12
-7
annotate_models_spec.rb
spec/annotate/annotate_models_spec.rb
+32
-0
No files found.
lib/annotate/annotate_models.rb
View file @
8056ecf0
...
@@ -377,13 +377,18 @@ module AnnotateModels
...
@@ -377,13 +377,18 @@ 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
)
ObjectSpace
.
each_object
(
::
Class
).
begin
select
do
|
c
|
ActiveSupport
::
Inflector
.
constantize
(
ActiveSupport
::
Inflector
.
camelize
(
model_path
))
Class
===
c
and
# note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
rescue
c
.
ancestors
.
respond_to?
(
:include?
)
and
# to fix FactoryGirl bug, see https://github.com/ctran/annotate_models/pull/82
# Revert to the old way but it is not really robust
c
.
ancestors
.
include?
(
ActiveRecord
::
Base
)
ObjectSpace
.
each_object
(
::
Class
).
end
.
select
do
|
c
|
detect
{
|
c
|
ActiveSupport
::
Inflector
.
underscore
(
c
)
==
model_path
}
Class
===
c
and
# note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
c
.
ancestors
.
respond_to?
(
:include?
)
and
# to fix FactoryGirl bug, see https://github.com/ctran/annotate_models/pull/82
c
.
ancestors
.
include?
(
ActiveRecord
::
Base
)
end
.
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
...
...
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