class YARD::Handlers::Ruby::ConstantHandler
Handles any constant assignment
Private Instance Methods
Source
# File lib/yard/handlers/ruby/constant_handler.rb, line 67 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
Extract the parameters from the Struct.new or Data.define AST node, returning them as a list of strings
@param [MethodCallNode] superclass the AST node for the Struct.new or Data.define call @return [Array<String>] the member names to generate methods for
Source
# File lib/yard/handlers/ruby/constant_handler.rb, line 24 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
Source
# File lib/yard/handlers/ruby/constant_handler.rb, line 47 def process_dataclass(statement) lhs = statement[0] if (lhs.type == :var_field && lhs[0].type == :const) || lhs.type == :const_path_field klass = create_class(lhs.source, P(:Data)) extract_parameters(statement[1]).each do |member| next if klass.attributes[:instance][member] klass.attributes[:instance][member] = SymbolHash[:read => nil, :write => nil] create_reader(klass, member) end parse_block(statement[1].block[1], :namespace => klass) unless statement[1].block.nil? else raise YARD::Parser::UndocumentableError, "Data assignment to #{lhs.source}" end end
Source
# File lib/yard/handlers/ruby/constant_handler.rb, line 36 def process_structclass(statement) lhs = statement[0] if (lhs.type == :var_field && lhs[0].type == :const) || lhs.type == :const_path_field klass = create_class(lhs.source, 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 #{lhs.source}" end end