(PDOC-25) Fix mangled puppet namespaces

Prior to this commit, puppet namespaces would be totally mangled when
processed by YARD since YARD is looking for Ruby namespaces where the
first letter of each segment must be uppercase.

In order to fix this, patch the relevant regular expression constants
in YARD so that they will accept segments that begin with uppercase
and lowercase letters.

An upstream pull request has been accepted into YARD to add another
regex constant which is necessary to complete this patch. However until
the next version of the YARD gem is released, we must include a temporary
hack to fix the problematic method in question (as it is not yet using
the added variable). Once the new version is released, the conditional
statement in code_ext/yard.rb can be removed entirely and all we will
need to do is patch the two regex constants.
This commit is contained in:
Hailee Kenney 2015-02-26 16:03:21 -08:00
parent 93e584524d
commit 685ebf54eb
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,40 @@
require 'yard'
require 'puppet_x/puppetlabs/strings'
# Patch the regular expression used to match namespaces
# so it will allow namespace segments that begin with
# both uppercase and lowercase letters (i.e. both
# Puppet::Namespace and puppet::namespace)
YARD::CodeObjects.send(:remove_const, :CONSTANTMATCH)
YARD::CodeObjects::CONSTANTMATCH = /[a-zA-Z]\w*/
# This is a temporary hack until a new version of YARD is
# released. We submitted a patch to YARD to add the
# CONSTANTSTART constant so that we could patch it and
# successfully match our own namesapces. However until
# the next version of the YARD gem is released, we must
# patch the problematic method itself as it is not yet
# using the added variable
if defined? YARD::CodeObjects::CONSTANTSTART
YARD::CodeObjects.send(:remove_const, :CONSTANTSTART)
YARD::CodeObjects::CONSTANTSTART = /^[a-zA-Z]/
else
class YARD::CodeObjects::Proxy
def proxy_path
if @namespace.root?
(@imethod ? YARD::CodeObjects::ISEP : "") + name.to_s
elsif @origname
if @origname =~ /^[a-zA-Z]/
@origname
else
[namespace.path, @origname].join
end
elsif name.to_s =~ /^[a-zA-Z]/ # const
name.to_s
else # class meth?
[namespace.path, name.to_s].join(YARD::CodeObjects::CSEP)
end
end
end
end

View File

@ -1,3 +1,5 @@
require 'puppet_x/puppetlabs/strings/yard/core_ext/yard'
class PuppetX::PuppetLabs::Strings::YARD::Handlers::Base < YARD::Handlers::Base class PuppetX::PuppetLabs::Strings::YARD::Handlers::Base < YARD::Handlers::Base
# Easy access to Pops model objects for handler matching. # Easy access to Pops model objects for handler matching.
include Puppet::Pops::Model include Puppet::Pops::Model