lib/yard/handlers/ruby/legacy/constant_handler.rb in yard-0.2.3.5 vs lib/yard/handlers/ruby/legacy/constant_handler.rb in yard-0.4.0

- old
+ new

@@ -5,9 +5,28 @@ def process # Don't document CONSTANTS if they're set in second class objects (methods) because # they're not "static" when executed from a method return unless owner.is_a? NamespaceObject - name, value = *statement.tokens.to_s.gsub(/\r?\n/, '').split(/\s*=\s*/, 2) - register ConstantObject.new(namespace, name) {|o| o.source = statement; o.value = value.strip } + name, value = *statement.tokens.to_s.split(/\s*=\s*/, 2) + if value =~ /\A\s*Struct.new(?:\s*\(?|\b)/ + process_structclass(name, $') + else + register ConstantObject.new(namespace, name) {|o| o.source = statement; o.value = value.strip } + end + end + + private + + def process_structclass(classname, parameters) + scope = :instance + klass = register ClassObject.new(namespace, classname) + klass.superclass = P(:Struct) + + tokval_list(YARD::Parser::Ruby::Legacy::TokenList.new(parameters), TkSYMBOL).each do |name| + klass.attributes[scope][name] = SymbolHash[:read => nil, :write => nil] + {:read => name, :write => "#{name}="}.each do |type, meth| + klass.attributes[scope][name][type] = MethodObject.new(klass, meth, scope) + end + end end end \ No newline at end of file