class YARD::Handlers::Ruby::ClassHandler
Handles class declarations
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_superclass(the_super, superclass_def) the_super end
def extract_parameters(superclass)
-
(Array
- the member names to generate methods for)
Parameters:
-
superclass
(MethodCallNode
) -- the AST node for the Struct.new call
def extract_parameters(superclass) members = superclass.parameters.select {|x| x && x.type == :symbol_literal } members.map! {|x| x.source.strip[1..-1] } members end
def parse_struct_superclass(klass, superclass)
def parse_struct_superclass(klass, superclass) return unless superclass.call? && superclass.parameters members = extract_parameters(superclass) create_attributes(klass, members) end
def parse_superclass(superclass)
def parse_superclass(superclass) return nil unless superclass case superclass.type when :var_ref return namespace.path if superclass.first == s(:kw, "self") return superclass.source if superclass.first.type == :const when :const, :const_ref, :const_path_ref, :top_const_ref return superclass.source when :fcall, :command methname = superclass.method_name.source return superclass.parameters.first.source if methname == "DelegateClass" return methname if superclass.method_name.type == :const when :call, :command_call cname = superclass.namespace.source if cname =~ /^O?Struct$/ && superclass.method_name(true) == :new return cname end end nil end
def struct_superclass_name(superclass)
def struct_superclass_name(superclass) if superclass.call? first = superclass.parameters.first if first.type == :string_literal && first[0].type == :string_content && first[0].size == 1 return "Struct::#{first[0][0][0]}" end end "Struct" end