Class: YARD::Handlers::Ruby::Legacy::ClassHandler

Inherits:
Base show all
Defined in:
lib/yard/handlers/ruby/legacy/class_handler.rb

Constant Summary

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

EXPR_ARG, EXPR_BEG, EXPR_CLASS, EXPR_DOT, EXPR_END, EXPR_FNAME, EXPR_MID, NEWLINE_TOKEN, TkReading2Token, TkSymbol2Token, TokenDefinitions

Constants included from YARD::CodeObjects

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

Instance Method Summary

Methods inherited from Base

handles?, #parse_block

Methods included from YARD::Parser::Ruby::Legacy::RubyToken

#Token, def_token, #set_token_position

Methods inherited from YARD::Handlers::Base

clear_subclasses, #ensure_loaded!, handlers, handles, handles?, #initialize, namespace_only, namespace_only?, #parse_block, #push_state, #register, subclasses

Constructor Details

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

Instance Method Details

- (Object) process



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/yard/handlers/ruby/legacy/class_handler.rb', line 4

def process
  if statement.tokens.to_s =~ /^class\s+(#{NAMESPACEMATCH})\s*(?:<\s*(.+)|\Z)/m
    classname = $1
    superclass = parse_superclass($2)
    undocsuper = $2 && superclass.nil?

    klass = register ClassObject.new(namespace, classname) do |o|
      o.superclass = superclass if superclass
      o.superclass.type = :class if o.superclass.is_a?(Proxy)
    end
    parse_block(:namespace => klass)
     
    if undocsuper
      raise YARD::Parser::UndocumentableError, 'superclass (class was added without superclass)'
    end
  elsif statement.tokens.to_s =~ /^class\s*<<\s*([\w\:]+)/
    classname = $1
    proxy = Proxy.new(namespace, classname)
    
    # Allow constants to reference class names
    if ConstantObject === proxy
      if proxy.value =~ /\A#{NAMESPACEMATCH}\Z/
        proxy = Proxy.new(namespace, proxy.value)
      else
        raise YARD::Parser::UndocumentableError, "constant class reference '#{classname}'"
      end
    end
    
    if classname == "self"
      parse_block(:namespace => namespace, :scope => :class)
    elsif classname[0,1] =~ /[A-Z]/ 
      register ClassObject.new(namespace, classname) if Proxy === proxy
      parse_block(:namespace => proxy, :scope => :class)
    else
      raise YARD::Parser::UndocumentableError, "class '#{classname}'"
    end
  else
    raise YARD::Parser::UndocumentableError, "class: #{statement.tokens}"
  end
end