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

Inherits:
Base
  • Object
show all
Includes:
StructHandlerMethods
Defined in:
lib/yard/handlers/ruby/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::CSEP, CodeObjects::CSEPQ, CodeObjects::ISEP, CodeObjects::ISEPQ, CodeObjects::METHODMATCH, CodeObjects::METHODNAMEMATCH, CodeObjects::NAMESPACEMATCH, CodeObjects::NSEP, CodeObjects::NSEPQ

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 Parser::Ruby

#s

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/class_handler.rb', line 7

process do
  classname = statement[0].source.gsub(/\s/, '')
  if statement.type == :class
    superclass = parse_superclass(statement[1])
    if superclass == "Struct"
      is_a_struct = true
      superclass = struct_superclass_name(statement[1]) # refine the superclass if possible
      create_struct_superclass(superclass, statement[1])
    end
    undocsuper = statement[1] && 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_superclass(klass, statement[1])
    elsif klass
      create_attributes(klass, members_from_tags(klass))
    end
    parse_block(statement[2], :namespace => klass)

    if undocsuper
      raise YARD::Parser::UndocumentableError, 'superclass (class was added without superclass)'
    end
  elsif statement.type == :sclass
    if statement[0] == s(:var_ref, s(:kw, "self"))
      parse_block(statement[1], :namespace => namespace, :scope => :class)
    else
      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[0,1] =~ /[A-Z]/
        register ClassObject.new(namespace, classname) if Proxy === proxy
        parse_block(statement[1], :namespace => proxy, :scope => :class)
      else
        raise YARD::Parser::UndocumentableError, "class '#{classname}'"
      end
    end
  else
    sig_end = (statement[1] ? statement[1].source_end : statement[0].source_end) - statement.source_start
    raise YARD::Parser::UndocumentableError, "class: #{statement.source[0..sig_end]}"
  end
end