Skip to content

Commit 87c092e

Browse files
authored
Merge pull request #819 from aycabta/support-included
Support ActiveSupport::Concern.included
2 parents ec17a3e + a2d651d commit 87c092e

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

lib/rdoc/parser/ruby.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,22 @@ def parse_extend_or_include klass, container, comment # :nodoc:
11931193
end
11941194
end
11951195

1196+
##
1197+
# Parses an +included+ with a block feature of ActiveSupport::Concern.
1198+
1199+
def parse_included_with_activesupport_concern container, comment # :nodoc:
1200+
skip_tkspace_without_nl
1201+
tk = get_tk
1202+
unless tk[:kind] == :on_lbracket || (tk[:kind] == :on_kw && tk[:text] == 'do')
1203+
unget_tk tk
1204+
return nil # should be a block
1205+
end
1206+
1207+
parse_statements container
1208+
1209+
container
1210+
end
1211+
11961212
##
11971213
# Parses identifiers that can create new methods or change visibility.
11981214
#
@@ -1893,6 +1909,8 @@ def parse_statements(container, single = NORMAL, current_method = nil,
18931909
parse_extend_or_include RDoc::Include, container, comment
18941910
when "extend" then
18951911
parse_extend_or_include RDoc::Extend, container, comment
1912+
when "included" then
1913+
parse_included_with_activesupport_concern container, comment
18961914
end
18971915

18981916
else

test/rdoc/test_rdoc_parser_ruby.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4297,4 +4297,52 @@ class D
42974297
assert_equal 'A::D', a_d.full_name
42984298
end
42994299

4300+
def test_parse_included
4301+
util_parser <<-CLASS
4302+
module A
4303+
module B
4304+
extend ActiveSupport::Concern
4305+
included do
4306+
##
4307+
# :singleton-method:
4308+
# Hello
4309+
mattr_accessor :foo
4310+
end
4311+
end
4312+
end
4313+
CLASS
4314+
4315+
@parser.scan
4316+
4317+
a = @store.find_module_named 'A'
4318+
assert_equal 'A', a.full_name
4319+
a_b = a.find_module_named 'B'
4320+
assert_equal 'A::B', a_b.full_name
4321+
meth = a_b.method_list.first
4322+
assert_equal 'foo', meth.name
4323+
assert_equal 'Hello', meth.comment.text
4324+
end
4325+
4326+
def test_end_that_doesnt_belong_to_class_doesnt_change_visibility
4327+
util_parser <<-CLASS
4328+
class A
4329+
private
4330+
4331+
begin
4332+
end
4333+
4334+
# Hello
4335+
def foo() end
4336+
end
4337+
CLASS
4338+
4339+
@parser.scan
4340+
4341+
a = @store.find_class_named 'A'
4342+
assert_equal 'A', a.full_name
4343+
assert_equal 'foo', a.find_method_named('foo').name
4344+
meth = a.method_list.first
4345+
assert_equal 'Hello', meth.comment.text
4346+
end
4347+
43004348
end

0 commit comments

Comments
 (0)