Module: TypeSpecFromSerializers::RDoc

Defined in:
lib/typespec_from_serializers/rdoc.rb

Overview

Public: RDoc integration for documentation extraction.

This module uses RDoc’s Prism-based parser to extract documentation comments from Ruby source files. It provides documentation for:

  1. Classes (serializers, controllers)

  2. Methods (controller actions, serializer attributes)

The module caches parsed files to avoid re-parsing the same file multiple times during a single generation run.

Requires RDoc 7.0+ for Prism parser support. Gracefully degrades to returning nil for all documentation when unavailable.

Class Method Summary collapse

Class Method Details

.available?Boolean

Public: Check if RDoc Prism parser is available.

Returns true if RDoc 7.0+ with Prism parser is available.

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
# File 'lib/typespec_from_serializers/rdoc.rb', line 23

def available?
  return @available if defined?(@available)

  @available = begin
    require "rdoc/parser/prism_ruby"
    true
  rescue LoadError
    false
  end
end

.class_doc(klass) ⇒ Object

Public: Get documentation for a class.

klass - The Class to get documentation for

Returns String or nil



39
40
41
# File 'lib/typespec_from_serializers/rdoc.rb', line 39

def class_doc(klass)
  find_rdoc_class(klass)&.then { extract_comment_text(_1.comment) }
end

.clear_cache!Object

Public: Clear the parse cache.

This should be called between generation runs if files may have changed.



59
60
61
# File 'lib/typespec_from_serializers/rdoc.rb', line 59

def clear_cache!
  @cache = {}
end

.method_doc(klass, method_name) ⇒ Object

Public: Get documentation for a method.

klass - The Class containing the method method_name - Symbol or String name of the method

Returns String or nil



49
50
51
52
53
54
# File 'lib/typespec_from_serializers/rdoc.rb', line 49

def method_doc(klass, method_name)
  find_rdoc_class(klass)
    &.method_list
    &.find { _1.name == method_name.to_s }
    &.then { extract_comment_text(_1.comment) }
end