class YARD::Handlers::Ruby::ClassHandler
Handles class declarations
Private Instance Methods
Source
# File lib/yard/handlers/ruby/class_handler.rb, line 73 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
Source
# File lib/yard/handlers/ruby/class_handler.rb, line 67 def extract_parameters(superclass) members = superclass.parameters.select {|x| x && x.type == :symbol_literal } members.map! {|x| x.source.strip[1..-1] } members end
Extract the parameters from the Struct.new AST node, returning them as a list of strings
@param [MethodCallNode] superclass the AST node for the Struct.new call @return [Array<String>] the member names to generate methods for
Source
# File lib/yard/handlers/ruby/class_handler.rb, line 92 def parse_struct_superclass(klass, superclass) return unless superclass.call? && superclass.parameters members = extract_parameters(superclass) create_attributes(klass, members) end
Source
# File lib/yard/handlers/ruby/class_handler.rb, line 98 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
Source
# File lib/yard/handlers/ruby/class_handler.rb, line 82 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