class YARD::Handlers::Ruby::Legacy::ClassHandler
(see Ruby::ClassHandler)
Private Instance Methods
create_struct_superclass(superclass, superclass_def)
click to toggle source
# File lib/yard/handlers/ruby/legacy/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_subclass(the_super, superclass_def) the_super end
extract_parameters(superstring)
click to toggle source
Extracts the parameter list from the Struct.new declaration and returns it formatted as a list of member names. Expects the user will have used symbols to define the struct member names
@param [String] superstring the string declaring the superclass @return [Array<String>] a list of member names
# File lib/yard/handlers/ruby/legacy/class_handler.rb, line 68 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
parse_struct_subclass(klass, superclass_def)
click to toggle source
# File lib/yard/handlers/ruby/legacy/class_handler.rb, line 93 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
parse_superclass(superclass)
click to toggle source
# File lib/yard/handlers/ruby/legacy/class_handler.rb, line 100 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
struct_superclass_name(superclass)
click to toggle source
# File lib/yard/handlers/ruby/legacy/class_handler.rb, line 82 def struct_superclass_name(superclass) if match = superclass.match(/\A(Struct)\.new\((.*?)\)/) 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