Merge pull request #27 from hkenney/issue/master/PDOC-25_patch_mangled_namespaces
(PDOC-25) Fix mangled puppet namespaces
This commit is contained in:
commit
56ab5f2817
|
@ -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
|
|
@ -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
|
||||||
|
|
|
@ -58,4 +58,17 @@ describe PuppetX::PuppetLabs::Strings::YARD::Handlers::DefinedTypeHandler do
|
||||||
|
|
||||||
expect(YARD::Registry.all).to be_empty
|
expect(YARD::Registry.all).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should generate the correct namespace " do
|
||||||
|
puppet_code = <<-PUPPET
|
||||||
|
define puppet_enterprise::mcollective::client::certs { }
|
||||||
|
PUPPET
|
||||||
|
|
||||||
|
parse(puppet_code, :puppet)
|
||||||
|
# If the namespace is not correctly generated, we will not be able to find the
|
||||||
|
# object via this name, meaning namespace will be nil
|
||||||
|
namespace = YARD::Registry.at("puppet_enterprise::mcollective::client::certs").namespace.to_s
|
||||||
|
|
||||||
|
expect(namespace).to_not be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,4 +46,17 @@ describe PuppetX::PuppetLabs::Strings::YARD::Handlers::HostClassHandler do
|
||||||
|
|
||||||
expect(the_hostclass).to document_a(:type => :hostclass, :docstring => "")
|
expect(the_hostclass).to document_a(:type => :hostclass, :docstring => "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should generate the correct namespace " do
|
||||||
|
puppet_code = <<-PUPPET
|
||||||
|
class puppet_enterprise::mcollective::client::certs { }
|
||||||
|
PUPPET
|
||||||
|
|
||||||
|
parse(puppet_code, :puppet)
|
||||||
|
# If the namespace is not correctly generated, we will not be able to find the
|
||||||
|
# object via this name, meaning namespace will be nil
|
||||||
|
namespace = YARD::Registry.at("puppet_enterprise::mcollective::client::certs")
|
||||||
|
|
||||||
|
expect(namespace).to_not be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue