Class: YARD::Handlers::Ruby::HandlesExtension

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/handlers/ruby/base.rb

Overview

To implement a custom handler matcher, subclass this class and implement #matches? to return whether a node matches the handler.

Examples:

A Custom Handler Matcher Extension

# Implements a handler that checks for a specific string
# in the node's source.
class MyExtension < HandlesExtension
  def matches?(node) node.source.include?(name) end
end

# This handler will handle any node where the source includes 'foo'
class MyHandler < Handlers::Ruby::Base
  handles MyExtension.new('foo')
end

Direct Known Subclasses

MethodCallWrapper, TestNodeWrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ HandlesExtension

Creates a new extension with a specific matcher value name

Parameters:

  • name (Object)

    the matcher value to check against #matches?



21
# File 'lib/yard/handlers/ruby/base.rb', line 21

def initialize(name) @name = name end

Instance Attribute Details

#nameString (readonly, protected)

Returns the extension matcher value.

Returns:

  • (String)

    the extension matcher value



31
32
33
# File 'lib/yard/handlers/ruby/base.rb', line 31

def name
  @name
end

Instance Method Details

#matches?(node) ⇒ Boolean

Tests if the node matches the handler

Parameters:

Returns:

  • (Boolean)

    whether the node matches the handler

Raises:

  • (NotImplementedError)


26
# File 'lib/yard/handlers/ruby/base.rb', line 26

def matches?(node) raise NotImplementedError end