class YARD::Handlers::Ruby::ConstantHandler

Handles any constant assignment
frozen_string_literal: true

def extract_parameters(superclass)

Returns:
  • (Array) - the member names to generate methods for

Parameters:
  • superclass (MethodCallNode) -- the AST node for the Struct.new call
def extract_parameters(superclass)
  return [] unless superclass.parameters
  members = superclass.parameters.select {|x| x && x.type == :symbol_literal }
  members.map! {|x| x.source.strip[1..-1] }
  members
end

def process_constant(statement)

def process_constant(statement)
  name = statement[0].source
  value = statement[1].source
  obj = P(namespace, name)
  if obj.is_a?(NamespaceObject) && obj.namespace == namespace
    raise YARD::Parser::UndocumentableError, "constant for existing #{obj.type} #{obj}"
  else
    ensure_loaded! obj.parent
    register ConstantObject.new(namespace, name) {|o| o.source = statement; o.value = value.strip }
  end
end

def process_structclass(statement)

def process_structclass(statement)
  lhs = statement[0][0]
  if lhs.type == :const
    klass = create_class(lhs[0], P(:Struct))
    create_attributes(klass, extract_parameters(statement[1]))
    parse_block(statement[1].block[1], :namespace => klass) unless statement[1].block.nil?
  else
    raise YARD::Parser::UndocumentableError, "Struct assignment to #{statement[0].source}"
  end
end