Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ActiveSupport::Concern.included #819

Merged
merged 1 commit into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,22 @@ def parse_extend_or_include klass, container, comment # :nodoc:
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.
#
Expand Down Expand Up @@ -1893,6 +1909,8 @@ def parse_statements(container, single = NORMAL, current_method = nil,
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
Expand Down
48 changes: 48 additions & 0 deletions test/rdoc/test_rdoc_parser_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4297,4 +4297,52 @@ class D
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