Sha256: 35585b9b492e953a3560c7f1c98983781fba8df545458874407702bac39b1cb0

Contents?: true

Size: 1.79 KB

Versions: 11

Compression:

Stored size: 1.79 KB

Contents

class YARD::Handlers::Ruby::Legacy::ClassHandler < YARD::Handlers::Ruby::Legacy::Base
  handles TkCLASS
  
  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
  
  private
  
  def parse_superclass(superclass)
    case superclass
    when /\A(#{NAMESPACEMATCH})(?:\s|\Z)/, 
         /\A(Struct|OStruct)\.new/,
         /\ADelegateClass\((.+?)\)\s*\Z/,
         /\A(#{NAMESPACEMATCH})\(/
      $1
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
yard-0.5.3 lib/yard/handlers/ruby/legacy/class_handler.rb
yard-0.5.2 lib/yard/handlers/ruby/legacy/class_handler.rb
yard-0.5.1p1 lib/yard/handlers/ruby/legacy/class_handler.rb
yard-0.5.1 lib/yard/handlers/ruby/legacy/class_handler.rb
yard-0.5.0 lib/yard/handlers/ruby/legacy/class_handler.rb
yard-0.4.0 lib/yard/handlers/ruby/legacy/class_handler.rb
yard-0.2.3.5 lib/yard/handlers/ruby/legacy/class_handler.rb
yard-0.2.3.4 lib/yard/handlers/ruby/legacy/class_handler.rb
yard-0.2.3.2 lib/yard/handlers/ruby/legacy/class_handler.rb
yard-0.2.3.3 lib/yard/handlers/ruby/legacy/class_handler.rb
yard-0.2.3 lib/yard/handlers/ruby/legacy/class_handler.rb