Skip to content

Commit

Permalink
Merge pull request #1212 from castwide/file_singleton_methods
Browse files Browse the repository at this point in the history
Generate documentation for File singleton methods
  • Loading branch information
lsegal authored Jan 22, 2019
2 parents 5699818 + a3f4f4a commit ce80848
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/yard/handlers/c/method_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ class YARD::Handlers::C::MethodHandler < YARD::Handlers::C::Base
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\(|\(\w+\))?(\w+)\)?,
\s*(-?\w+)\s*\)/xm
MATCH3 = /define_filetest_function\s*\(
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\(|\(\w+\))?(\w+)\)?,
\s*(-?\w+)\s*\)/xm
handles MATCH1
handles MATCH2
handles MATCH3
statement_class BodyStatement

process do
Expand All @@ -32,5 +37,9 @@ class YARD::Handlers::C::MethodHandler < YARD::Handlers::C::Base
statement.source.scan(MATCH2) do |name, func_name, _param_count|
handle_method("method", "rb_mKernel", name, func_name)
end

statement.source.scan(MATCH3) do |name, func_name, _param_count|
handle_method("singleton_method", "rb_cFile", name, func_name)
end
end
end
13 changes: 13 additions & 0 deletions spec/parser/c_parser_spec.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ def parse(contents)
expect(Registry.at('Foo#func').docstring).to eq "docstring"
end
end

describe "File singleton methods" do
before(:all) do
file = File.join(File.dirname(__FILE__), 'examples', 'file.c.txt')
parse(File.read(file))
end

it "parses methods from define_filetest_function" do
obj = YARD::Registry.at('File.exist?')
expect(obj).not_to be nil
expect(obj.docstring).not_to be_blank
end
end
end

describe "Override comments" do
Expand Down
28 changes: 28 additions & 0 deletions spec/parser/examples/file.c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
VALUE rb_cFile;

/*
* call-seq:
* File.exist?(file_name) -> true or false
*
* Return <code>true</code> if the named file exists.
*
* _file_name_ can be an IO object.
*
* "file exists" means that stat() or fstat() system call is successful.
*/

static VALUE
rb_file_exist_p(VALUE obj, VALUE fname)
{
struct stat st;

if (rb_stat(fname, &st) < 0) return Qfalse;
return Qtrue;
}

void
Init_File(void)
{
rb_cFile = rb_define_class("File", rb_cIO);
define_filetest_function("exist?", rb_file_exist_p, 1);
}

0 comments on commit ce80848

Please sign in to comment.