Extract class parameters from parser output
Re-worked the YARD transformer and handlers to attach parameters to the resulting code objects. Some architectural debt was incurred in the interests of producing a working prototype quickly.
This commit is contained in:
parent
e98761100d
commit
005a8521bd
|
@ -1,3 +1,4 @@
|
|||
require 'ostruct'
|
||||
require 'puppet/pops'
|
||||
|
||||
require_relative '../../yardoc'
|
||||
|
@ -5,10 +6,17 @@ require_relative '../../yardoc'
|
|||
module Puppetx::Yardoc::Pops
|
||||
# An adapter class that conforms a Pops model instance + adapters to the
|
||||
# interface expected by YARD handlers.
|
||||
class YARDStatement
|
||||
#
|
||||
# FIXME: Inhertiting from OpenStruct is a bit of a hack. It allows attributes
|
||||
# to be declared as needed but in the long run understandibility of the code
|
||||
# would be improved by having a concrete model.
|
||||
class YARDStatement < OpenStruct
|
||||
attr_reader :pops_obj, :comments
|
||||
|
||||
def initialize(pops_obj)
|
||||
# Initialize OpenStruct
|
||||
super({})
|
||||
|
||||
unless pops_obj.is_a? Puppet::Pops::Model::PopsObject
|
||||
raise ArgumentError, "A YARDStatement can only be initialized from a PopsObject. Got a: #{pops_obj.class}"
|
||||
end
|
||||
|
|
|
@ -29,12 +29,21 @@ module Puppetx::Yardoc::Pops
|
|||
o.definitions.map{|d| transform(d)}
|
||||
end
|
||||
|
||||
# Extract comments from "Definition" objects. That is: nodes definitions,
|
||||
# type definitions and class definitions. Wrap them into YARDStatement
|
||||
# objects that provide an interface for YARD handlers.
|
||||
def transform_Definition(o)
|
||||
YARDStatement.new(o)
|
||||
# Extract comments from type definitions and class definitions. Wrap them
|
||||
# into YARDStatement objects that provide an interface for YARD handlers.
|
||||
def transform_NamedDefinition(o)
|
||||
obj = YARDStatement.new(o)
|
||||
obj.parameters = o.parameters.map do |p|
|
||||
param_tuple = [transform(p)]
|
||||
param_tuple << ( p.value.nil? ? nil : transform(p.value) )
|
||||
end
|
||||
|
||||
obj
|
||||
end
|
||||
|
||||
# Catch-all visitor.
|
||||
def transform_Positioned(o)
|
||||
YARDStatement.new(o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,10 @@ module Puppetx::Yardoc::YARD::CodeObjects
|
|||
# @return [HostClassObject, Proxy, nil]
|
||||
attr_accessor :parent_class
|
||||
|
||||
# A list of parameters attached to this class.
|
||||
# @return [Array<Array(String, String)>]
|
||||
attr_accessor :parameters
|
||||
|
||||
# The `YARD::Codeobjects::Base` class pulls a bunch of shenanigans to
|
||||
# insert proxy namespaces. Unfortunately, said shenanigans pick up on the
|
||||
# `::` in Puppet names and start to mangle things based on rules for the
|
||||
|
|
|
@ -5,7 +5,12 @@ module Puppetx::Yardoc::YARD::Handlers
|
|||
handles HostClassDefinition
|
||||
|
||||
process do
|
||||
obj = HostClassObject.new(:root, statement.pops_obj.name)
|
||||
obj = HostClassObject.new(:root, statement.pops_obj.name) do |o|
|
||||
o.parameters = statement.parameters.map do |a|
|
||||
param_tuple = [a[0].pops_obj.name]
|
||||
param_tuple << ( a[1].nil? ? nil : a[1].source )
|
||||
end
|
||||
end
|
||||
|
||||
statement.pops_obj.tap do |o|
|
||||
if o.parent_class
|
||||
|
|
Loading…
Reference in New Issue