From 0307f0f5e99a6c7fd242058e7b06315b5c76b457 Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Thu, 12 Jun 2014 18:33:26 -0700 Subject: [PATCH] Add new PuppetNamespaceObject class This class is functionally equivalent to the ModuleObject class that YARD uses for Ruby code. Using a new class allows us to gather YARD objects related to Puppet and separate them from the Ruby bits. --- lib/puppetx/yardoc/yard/code_objects.rb | 1 + .../yard/code_objects/defined_type_object.rb | 24 ++----------- .../code_objects/puppet_namespace_object.rb | 36 +++++++++++++++++++ 3 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 lib/puppetx/yardoc/yard/code_objects/puppet_namespace_object.rb diff --git a/lib/puppetx/yardoc/yard/code_objects.rb b/lib/puppetx/yardoc/yard/code_objects.rb index e9df3dd..b87b4ad 100644 --- a/lib/puppetx/yardoc/yard/code_objects.rb +++ b/lib/puppetx/yardoc/yard/code_objects.rb @@ -1,2 +1,3 @@ +require_relative 'code_objects/puppet_namespace_object' require_relative 'code_objects/defined_type_object' require_relative 'code_objects/host_class_object' diff --git a/lib/puppetx/yardoc/yard/code_objects/defined_type_object.rb b/lib/puppetx/yardoc/yard/code_objects/defined_type_object.rb index 8be8817..0e6db15 100644 --- a/lib/puppetx/yardoc/yard/code_objects/defined_type_object.rb +++ b/lib/puppetx/yardoc/yard/code_objects/defined_type_object.rb @@ -1,31 +1,11 @@ -require 'yard' require 'puppet/pops' -require_relative '../../../yardoc' +require_relative 'puppet_namespace_object' module Puppetx::Yardoc::YARD::CodeObjects - class DefinedTypeObject < YARD::CodeObjects::NamespaceObject + class DefinedTypeObject < PuppetNamespaceObject # A list of parameters attached to this class. # @return [Array] attr_accessor :parameters - - # NOTE: `YARD::Registry#resolve` requires a method with this signature to - # be present on all subclasses of `NamespaceObject`. - def inheritance_tree(include_mods = false) - [self] - end - - # FIXME: We used to override `self.new` to ensure no YARD proxies were - # created for namespaces segments that did not map to a host class or - # defined type. Fighting the system in this way turned out to be - # counter-productive. - # - # However, if a proxy is left in, YARD will drop back to namspace-mangling - # heuristics that are very specific to Ruby and which produce ugly paths in - # the resulting output. Consider walking the namespace tree for each new - # class/type and ensuring that a placeholder other than a YARD proxy is - # used. - # - # def self.new(namespace, name, *args, &block) end end diff --git a/lib/puppetx/yardoc/yard/code_objects/puppet_namespace_object.rb b/lib/puppetx/yardoc/yard/code_objects/puppet_namespace_object.rb new file mode 100644 index 0000000..2aa4a90 --- /dev/null +++ b/lib/puppetx/yardoc/yard/code_objects/puppet_namespace_object.rb @@ -0,0 +1,36 @@ +require 'yard' + +require_relative '../../../yardoc' + +module Puppetx::Yardoc::YARD::CodeObjects + class PuppetNamespaceObject < YARD::CodeObjects::NamespaceObject + # NOTE: `YARD::Registry#resolve` requires a method with this signature to + # be present on all subclasses of `NamespaceObject`. + def inheritance_tree(include_mods = false) + [self] + end + + # FIXME: We used to override `self.new` to ensure no YARD proxies were + # created for namespaces segments that did not map to a host class or + # defined type. Fighting the system in this way turned out to be + # counter-productive. + # + # However, if a proxy is left in, YARD will drop back to namspace-mangling + # heuristics that are very specific to Ruby and which produce ugly paths in + # the resulting output. Need to find a way to address this. + # + # Tried: + # + # - Overriding self.new in the code object. Failed because self.new + # overrides are gross and difficult to pull off. Especially when + # replacing an existing override. + # + # - Adding functionality to the base handler to ensure something other + # than a proxy occupies each namespace segment. Failed because once a + # code object is created with a namespace, it will never update. + # Unless that namespace is set to a Proxy. + # + # def self.new(namespace, name, *args, &block) + end +end +