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

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

Overview

Handles class declarations

Constant Summary

Constants included from CodeObjects

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

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

Instance Method Summary collapse

Methods included from StructHandlerMethods

#add_reader_tags, #add_writer_tags, #create_attributes, #create_class, #create_member_method?, #create_reader, #create_writer, #member_tag_for_member, #members_from_tags, #return_type_from_tag

Methods included from CodeObjects::NamespaceMapper

#clear_separators, #default_separator, #register_separator, #separators, #separators_for_type, #separators_match, #types_for_separator

Constructor Details

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

Instance Method Details

#processvoid

This method returns an undefined value.

Main processing callback



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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/yard/handlers/ruby/legacy/class_handler.rb', line 8

process do
  if statement.tokens.to_s =~ /^class\s+(#{NAMESPACEMATCH})\s*(?:<\s*(.+)|\Z)/m
    classname = $1
    superclass_def = $2
    superclass = parse_superclass($2)
    classname = classname.gsub(/\s/, '')
    if superclass == "Struct"
      is_a_struct = true
      superclass = struct_superclass_name(superclass_def)
      create_struct_superclass(superclass, superclass_def)
    end
    undocsuper = superclass_def && 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
    if is_a_struct
      parse_struct_subclass(klass, superclass_def)
    elsif klass
      create_attributes(klass, members_from_tags(klass))
    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\:\s]+)/
    classname = $1.gsub(/\s/, '')
    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