[前][次][番号順一覧][スレッド一覧]

ruby-changes:26439

From: drbrain <ko1@a...>
Date: Thu, 20 Dec 2012 15:23:39 +0900 (JST)
Subject: [ruby-changes:26439] drbrain:r38490 (trunk): * lib/rdoc/parser/ruby.rb: Ignore methods defined on constants to

drbrain	2012-12-20 15:23:28 +0900 (Thu, 20 Dec 2012)

  New Revision: 38490

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38490

  Log:
    * lib/rdoc/parser/ruby.rb:  Ignore methods defined on constants to
      prevent modules with the names of constants from appearing in the
      documentation.
    * test/rdoc/test_rdoc_parser_ruby.rb:  Test for the above.

  Modified files:
    trunk/ChangeLog
    trunk/lib/rdoc/parser/ruby.rb
    trunk/test/rdoc/test_rdoc_parser_ruby.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38489)
+++ ChangeLog	(revision 38490)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Dec 20 15:22:59 2012  Eric Hodel  <drbrain@s...>
+
+	* lib/rdoc/parser/ruby.rb:  Ignore methods defined on constants to
+	  prevent modules with the names of constants from appearing in the
+	  documentation.
+	* test/rdoc/test_rdoc_parser_ruby.rb:  Test for the above.
+
 Thu Dec 20 16:00:33 2012  Martin Bosslet  <Martin.Bosslet@g...>
 
 	* ext/openssl/ossl_cipher.c: add support for Authenticated Encryption
Index: lib/rdoc/parser/ruby.rb
===================================================================
--- lib/rdoc/parser/ruby.rb	(revision 38489)
+++ lib/rdoc/parser/ruby.rb	(revision 38490)
@@ -1116,6 +1116,18 @@ class RDoc::Parser::Ruby < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/ruby.rb#L1116
           name = name_t2.name
           prev_container = container
           container = container.find_module_named(name_t.name)
+
+          unless container then
+            constant = prev_container.constants.find do |const|
+              const.name == name_t.name
+            end
+
+            if constant then
+              parse_method_dummy prev_container
+              return
+            end
+          end
+
           unless container then
             added_container = true
             obj = name_t.name.split("::").inject(Object) do |state, item|
@@ -1138,10 +1150,7 @@ class RDoc::Parser::Ruby < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/ruby.rb#L1150
             container.record_location @top_level
           end
         when TkIDENTIFIER, TkIVAR, TkGVAR then
-          dummy = RDoc::Context.new
-          dummy.parent = container
-          dummy.store  = container.store
-          skip_method dummy
+          parse_method_dummy container
           return
         when TkTRUE, TkFALSE, TkNIL then
           klass_name = "#{name_t.name.capitalize}Class"
@@ -1229,6 +1238,16 @@ class RDoc::Parser::Ruby < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/ruby.rb#L1238
   end
 
   ##
+  # Parses a method that needs to be ignored.
+
+  def parse_method_dummy container
+    dummy = RDoc::Context.new
+    dummy.parent = container
+    dummy.store  = container.store
+    skip_method dummy
+  end
+
+  ##
   # Extracts +yield+ parameters from +method+
 
   def parse_method_or_yield_parameters(method = nil,
Index: test/rdoc/test_rdoc_parser_ruby.rb
===================================================================
--- test/rdoc/test_rdoc_parser_ruby.rb	(revision 38489)
+++ test/rdoc/test_rdoc_parser_ruby.rb	(revision 38490)
@@ -1525,6 +1525,21 @@ end https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_ruby.rb#L1525
     assert            ampersand.singleton
   end
 
+  def test_parse_method_constant
+    c = RDoc::Constant.new 'CONST', nil, ''
+    m = @top_level.add_class RDoc::NormalModule, 'M'
+    m.add_constant c
+
+    util_parser "def CONST.m() end"
+
+    tk = @parser.get_tk
+
+    @parser.parse_method m, RDoc::Parser::Ruby::NORMAL, tk, @comment
+
+    assert_empty @store.modules_hash.keys
+    assert_equal %w[M], @store.classes_hash.keys
+  end
+
   def test_parse_method_false
     util_parser "def false.foo() :bar end"
 
@@ -1766,6 +1781,14 @@ end https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_ruby.rb#L1781
     assert_equal "def \317\211", omega.text
   end
 
+  def test_parse_method_dummy
+    util_parser ".method() end"
+
+    @parser.parse_method_dummy @top_level
+
+    assert_nil @parser.get_tk
+  end
+
   def test_parse_method_or_yield_parameters_hash
     util_parser "({})\n"
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]