Skip to content

Commit

Permalink
Merge pull request #819 from aycabta/support-included
Browse files Browse the repository at this point in the history
Support ActiveSupport::Concern.included
  • Loading branch information
aycabta authored Jun 30, 2021
2 parents ec17a3e + a2d651d commit 87c092e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
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

0 comments on commit 87c092e

Please sign in to comment.