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

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

Constant Summary

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?, meta_type, method_call, #parse_block

Methods included from YARD::Parser::Ruby

#s

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



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
44
45
46
47
# File 'lib/yard/handlers/ruby/class_handler.rb', line 5

def process
  if statement.type == :class
    classname = statement[0].source
    superclass = parse_superclass(statement[1])
    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
    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
      classname = statement[0].source
      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