Class: Docscribe::Plugin::Base::CollectorPlugin

Inherits:
Object
  • Object
show all
Defined in:
lib/docscribe/plugin/base/collector_plugin.rb

Overview

Base class for collector plugins.

CollectorPlugins receive the raw AST and source buffer directly. They walk the tree themselves and return insertion targets that Docscribe will document according to the selected strategy.

Idempotency is handled by Docscribe:

  • :safe => skip if a doc-like block already exists above anchor_node

  • :aggressive => replace existing doc block above anchor_node

Examples:

Minimal plugin

class MyPlugin < Docscribe::Plugin::Base::CollectorPlugin
  def collect(ast, buffer)
    results = []

    ASTWalk.walk(ast) do |node|
      next unless node.type == :send
      recv, meth, *args = *node
      next unless recv.nil? && meth == :my_dsl_method

      results << {
        anchor_node: node,
        doc: "# My generated doc\n# @return [void]\n"
      }
    end

    results
  end
end

Docscribe::Plugin::Registry.register(MyPlugin.new)

Instance Method Summary collapse

Instance Method Details

#collect(_ast, _buffer) ⇒ Array<Hash>

Walk the AST and return documentation insertion targets.

Each result is a Hash with:

  • :anchor_node => Parser::AST::Node — node above which to insert doc

  • :doc => String — complete doc block including newlines

Parameters:

  • ast (Parser::AST::Node)

    root AST node of the file

  • buffer (Parser::Source::Buffer)

    source buffer

  • _ast (Object)

    Param documentation.

  • _buffer (Object)

    Param documentation.

Returns:

  • (Array<Hash>)


49
50
51
# File 'lib/docscribe/plugin/base/collector_plugin.rb', line 49

def collect(_ast, _buffer)
  []
end