ruby-changes:66689
From: aycabta <ko1@a...>
Date: Mon, 5 Jul 2021 18:35:33 +0900 (JST)
Subject: [ruby-changes:66689] caa123b50e (master): [ruby/rdoc] Support ActiveSupport::Concern.included
https://git.ruby-lang.org/ruby.git/commit/?id=caa123b50e From caa123b50e12c5ea95763d7661adb6096e48df21 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Tue, 29 Jun 2021 20:01:46 +0900 Subject: [ruby/rdoc] Support ActiveSupport::Concern.included ref. https://github.com/rails/rails/blob/168ddaa08a63cd956bb7c3ba10be1a7ae36d4ee2/activerecord/lib/active_record/core.rb#L9-L20 https://github.com/ruby/rdoc/commit/a2d651dade Co-authored-by: Fumiaki MATSUSHIMA <mtsmfm@g...> --- lib/rdoc/parser/ruby.rb | 18 ++++++++++++++ test/rdoc/test_rdoc_parser_ruby.rb | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index 8d021f3..e546fe2 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -1194,6 +1194,22 @@ class RDoc::Parser::Ruby < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/ruby.rb#L1194 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. # # Returns true if the comment was not consumed. @@ -1893,6 +1909,8 @@ class RDoc::Parser::Ruby < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/ruby.rb#L1909 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 diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index 0c81906..337cf9e 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -4297,4 +4297,52 @@ end https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_ruby.rb#L4297 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 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/