class YARD::Handlers::Ruby::Legacy::ClassHandler

(see Ruby::ClassHandler)
frozen_string_literal: true

def create_struct_superclass(superclass, superclass_def)

def create_struct_superclass(superclass, superclass_def)
  return if superclass == "Struct"
  the_super = register ClassObject.new(P("Struct"), superclass[8..-1]) do |o|
    o.superclass = "Struct"
  end
  parse_struct_subclass(the_super, superclass_def)
  the_super
end

def extract_parameters(superstring)

Returns:
  • (Array) - a list of member names

Parameters:
  • superstring (String) -- the string declaring the superclass
def extract_parameters(superstring)
  paramstring = superstring.match(/\A(O?Struct)\.new\((.*?)\)/)[2]
  paramstring.split(",").select {|x| x.strip[0, 1] == ":" }.map {|x| x.strip[1..-1] } # the 1..-1 chops the leading :
end

def parse_struct_subclass(klass, superclass_def)

def parse_struct_subclass(klass, superclass_def)
  # Bounce if there's no parens
  return unless superclass_def =~ /O?Struct\.new\((.*?)\)/
  members = extract_parameters(superclass_def)
  create_attributes(klass, members)
end

def parse_superclass(superclass)

def parse_superclass(superclass)
  case superclass
  when /\A(#{NAMESPACEMATCH})(?:\s|\Z)/,
       /\A(Struct|OStruct)\.new/,
       /\ADelegateClass\((.+?)\)\s*\Z/,
       /\A(#{NAMESPACEMATCH})\(/
    $1
  when "self"
    namespace.path
  end
end

def struct_superclass_name(superclass)

def struct_superclass_name(superclass)
  match = superclass.match(/\A(Struct)\.new\((.*?)\)/)
  if match
    paramstring = match[2].split(",")
    first = paramstring.first.strip
    if first[0, 1] =~ /['"]/ && first[-1, 1] =~ /['"]/ && first !~ /\#\{/
      return "Struct::#{first[1..-2]}"
    end
  end
  "Struct"
end