mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/rdoc] Support ActiveSupport::Concern.included
ref. 168ddaa08a/activerecord/lib/active_record/core.rb (L9-L20)
https://github.com/ruby/rdoc/commit/a2d651dade
Co-authored-by: Fumiaki MATSUSHIMA <mtsmfm@gmail.com>
This commit is contained in:
parent
2f3edf28f3
commit
caa123b50e
2 changed files with 66 additions and 0 deletions
|
@ -1193,6 +1193,22 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Parses an +included+ with a block feature of ActiveSupport::Concern.
|
||||
|
||||
def parse_included_with_activesupport_concern container, comment # :nodoc:
|
||||
skip_tkspace_without_nl
|
||||
tk = get_tk
|
||||
unless tk[:kind] == :on_lbracket || (tk[:kind] == :on_kw && tk[:text] == 'do')
|
||||
unget_tk tk
|
||||
return nil # should be a block
|
||||
end
|
||||
|
||||
parse_statements container
|
||||
|
||||
container
|
||||
end
|
||||
|
||||
##
|
||||
# Parses identifiers that can create new methods or change visibility.
|
||||
#
|
||||
|
@ -1893,6 +1909,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||
parse_extend_or_include RDoc::Include, container, comment
|
||||
when "extend" then
|
||||
parse_extend_or_include RDoc::Extend, container, comment
|
||||
when "included" then
|
||||
parse_included_with_activesupport_concern container, comment
|
||||
end
|
||||
|
||||
else
|
||||
|
|
|
@ -4297,4 +4297,52 @@ end
|
|||
assert_equal 'A::D', a_d.full_name
|
||||
end
|
||||
|
||||
def test_parse_included
|
||||
util_parser <<-CLASS
|
||||
module A
|
||||
module B
|
||||
extend ActiveSupport::Concern
|
||||
included do
|
||||
##
|
||||
# :singleton-method:
|
||||
# Hello
|
||||
mattr_accessor :foo
|
||||
end
|
||||
end
|
||||
end
|
||||
CLASS
|
||||
|
||||
@parser.scan
|
||||
|
||||
a = @store.find_module_named 'A'
|
||||
assert_equal 'A', a.full_name
|
||||
a_b = a.find_module_named 'B'
|
||||
assert_equal 'A::B', a_b.full_name
|
||||
meth = a_b.method_list.first
|
||||
assert_equal 'foo', meth.name
|
||||
assert_equal 'Hello', meth.comment.text
|
||||
end
|
||||
|
||||
def test_end_that_doesnt_belong_to_class_doesnt_change_visibility
|
||||
util_parser <<-CLASS
|
||||
class A
|
||||
private
|
||||
|
||||
begin
|
||||
end
|
||||
|
||||
# Hello
|
||||
def foo() end
|
||||
end
|
||||
CLASS
|
||||
|
||||
@parser.scan
|
||||
|
||||
a = @store.find_class_named 'A'
|
||||
assert_equal 'A', a.full_name
|
||||
assert_equal 'foo', a.find_method_named('foo').name
|
||||
meth = a.method_list.first
|
||||
assert_equal 'Hello', meth.comment.text
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue