Class: YARD::Handlers::Ruby::Legacy::Base Abstract

Inherits:
Base
  • Object
show all
Includes:
Parser::Ruby::Legacy::RubyToken
Defined in:
lib/yard/handlers/ruby/legacy/base.rb

Overview

This class is abstract.

See Base for subclassing information.

This is the base handler for the legacy parser. To implement a legacy handler, subclass this class.

Direct Known Subclasses

AliasHandler, AttributeHandler, ClassConditionHandler, ClassHandler, ClassVariableHandler, CommentHandler, ConstantHandler, DSLHandler, ExceptionHandler, MethodHandler, MixinHandler, ModuleFunctionHandler, ModuleHandler, PrivateClassMethodHandler, PrivateConstantHandler, VisibilityHandler, YieldHandler

Constant Summary

Constant Summary

Constants included from Parser::Ruby::Legacy::RubyToken

Parser::Ruby::Legacy::RubyToken::EXPR_ARG, Parser::Ruby::Legacy::RubyToken::EXPR_BEG, Parser::Ruby::Legacy::RubyToken::EXPR_CLASS, Parser::Ruby::Legacy::RubyToken::EXPR_DOT, Parser::Ruby::Legacy::RubyToken::EXPR_END, Parser::Ruby::Legacy::RubyToken::EXPR_FNAME, Parser::Ruby::Legacy::RubyToken::EXPR_MID, Parser::Ruby::Legacy::RubyToken::NEWLINE_TOKEN, Parser::Ruby::Legacy::RubyToken::TkReading2Token, Parser::Ruby::Legacy::RubyToken::TkSymbol2Token

Constants included from CodeObjects

CodeObjects::BUILTIN_ALL, CodeObjects::BUILTIN_CLASSES, CodeObjects::BUILTIN_EXCEPTIONS, CodeObjects::BUILTIN_EXCEPTIONS_HASH, CodeObjects::BUILTIN_MODULES, CodeObjects::CONSTANTMATCH, CodeObjects::CSEP, CodeObjects::CSEPQ, CodeObjects::ISEP, CodeObjects::ISEPQ, CodeObjects::METHODMATCH, CodeObjects::METHODNAMEMATCH, CodeObjects::NAMESPACEMATCH, CodeObjects::NSEP, CodeObjects::NSEPQ

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

This class inherits a constructor from YARD::Handlers::Base

Instance Attribute Details

- (Object) extra_state (readonly) Originally defined in class Base

Returns the value of attribute extra_state

- (Object) globals (readonly) Originally defined in class Base

Returns the value of attribute globals

- (Object) namespace Originally defined in class Base

Returns the value of attribute namespace

- (Object) owner Originally defined in class Base

Returns the value of attribute owner

- (Processor) parser (readonly) Originally defined in class Base

Returns the processor object that manages all global state during handling.

Returns:

  • (Processor)

    the processor object that manages all global state during handling.

- (Object) scope Originally defined in class Base

Returns the value of attribute scope

- (Object) statement (readonly) Originally defined in class Base

Returns the statement object currently being processed. Usually refers to one semantic language statement, though the strict definition depends on the parser used.

Returns:

  • (Object)

    the statement object currently being processed. Usually refers to one semantic language statement, though the strict definition depends on the parser used.

- (Object) visibility Originally defined in class Base

Returns the value of attribute visibility

Class Method Details

+ (Boolean) handles?(stmt)

Returns whether or not a Parser::Ruby::Legacy::Statement object should be handled by this handler.

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yard/handlers/ruby/legacy/base.rb', line 14

def self.handles?(stmt)
  handlers.any? do |a_handler|
    case a_handler
    when String
      stmt.tokens.first.text == a_handler
    when Regexp
      stmt.tokens.to_s =~ a_handler
    else
      a_handler == stmt.tokens.first.class
    end
  end
end

Instance Method Details

- (Object) call_params



43
44
45
46
47
48
49
50
51
52
# File 'lib/yard/handlers/ruby/legacy/base.rb', line 43

def call_params
  if statement.tokens.first.is_a?(TkDEF)
    extract_method_details.last.map {|param| param.first }
  else
    tokens = statement.tokens[1..-1]
    tokval_list(tokens, :attr, :identifier, TkId).map do |value|
      value.to_s
    end
  end
end

- (Object) caller_method



54
55
56
57
58
59
60
61
62
# File 'lib/yard/handlers/ruby/legacy/base.rb', line 54

def caller_method
  if statement.tokens.first.is_a?(TkIDENTIFIER)
    statement.tokens.first.text
  elsif statement.tokens.first.is_a?(TkDEF)
    extract_method_details.first
  else
    nil
  end
end

- (Object) parse_block(opts = {})

Parses a statement's block with a set of state values. If the statement has no block, nothing happens. A description of state values can be found at Base#push_state

Parameters:

  • opts (Hash) (defaults to: {})

    State options

Options Hash (opts):

  • :namespace (CodeObjects::NamespaceObject) — default: value of #namespace

    the namespace object that Base#namespace will be equal to for the duration of the block.

  • :scope (Symbol) — default: :instance

    the scope for the duration of the block.

  • :owner (CodeObjects::Base) — default: value of #owner

    the owner object (method) for the duration of the block

See Also:



34
35
36
37
38
39
40
41
# File 'lib/yard/handlers/ruby/legacy/base.rb', line 34

def parse_block(opts = {})
  push_state(opts) do
    if statement.block
      blk = Parser::Ruby::Legacy::StatementList.new(statement.block)
      parser.process(blk)
    end
  end
end