Skip to content

Commit

Permalink
Support ActiveSupport::Concern.included
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta and mtsmfm committed Jun 29, 2021
1 parent 59e4cc0 commit a2d651d
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

1 comment on commit a2d651d

@jeremyevans
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my knowledge, this is the first time we've included Rails-specific code in rdoc. I'm against this, because it either unfairly treats other libraries or we would have to accept similar patches for other libraries. What is the justification for including Rails-specific code here?

Please sign in to comment.