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

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::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 Attribute Summary

Attributes inherited from Base

#extra_state, #globals, #namespace, #owner, #parser, #scope, #statement, #visibility

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 inherited from Base

#call_params, #caller_method, handles?, #parse_block

Methods inherited from Base

#call_params, #caller_method, clear_subclasses, #ensure_loaded!, #expand_macro, #find_or_create_macro, handlers, handles, handles?, in_file, #initialize, matches_file?, namespace_only, namespace_only?, #parse_block, process, #push_state, #register, subclasses

Constructor Details

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

Instance Method Details

#processvoid

This method returns an undefined value.

Main processing callback



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

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