(PDOC-26) Rename Puppetx to PuppetX

Due to the changes in PUP-3900 which renamed Puppetx to PuppetX
and puppetx to puppet_x, strings was failing since the namespace
had not been updated in strings. In order to be compatible with this
change, update strings by renaming the namespace to match.

In order to ensure strings is still compatible with earlier versions
of puppet that don't include the namespace change, declare our own
PuppetX module. This way, if it is an older version and the namespace
is called Puppetx, the necessary PuppetX namespace will be created.
This commit is contained in:
Hailee Kenney 2015-02-03 15:06:30 -08:00
parent 06959d4c44
commit e5691d23c7
43 changed files with 59 additions and 57 deletions

View File

@ -33,9 +33,9 @@ Puppet::Face.define(:strings, '0.0.1') do
when_invoked do |*args| when_invoked do |*args|
check_required_features check_required_features
require 'puppetx/puppetlabs/strings/actions' require 'puppet_x/puppetlabs/strings/actions'
yardoc_actions = Puppetx::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace]) yardoc_actions = PuppetX::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace])
# The last element of the argument array should be the options hash. # The last element of the argument array should be the options hash.
# We don't have any options yet, so for now just pop the hash off and # We don't have any options yet, so for now just pop the hash off and
@ -65,9 +65,9 @@ Puppet::Face.define(:strings, '0.0.1') do
when_invoked do |*args| when_invoked do |*args|
check_required_features check_required_features
require 'puppetx/puppetlabs/strings/actions' require 'puppet_x/puppetlabs/strings/actions'
server_actions = Puppetx::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace]) server_actions = PuppetX::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace])
args.pop args.pop

View File

@ -1,48 +1,50 @@
require 'puppet' require 'puppet'
require 'puppet/pops' require 'puppet/pops'
require 'puppetx'
require 'puppet/util/docs' require 'puppet/util/docs'
require 'yard' require 'yard'
module PuppetX
end
# Nothing to see here except forward declarations. # Nothing to see here except forward declarations.
module Puppetx::PuppetLabs module PuppetX::PuppetLabs
module Strings module Strings
# This submodule contains bits that operate on the Pops module produced by # This submodule contains bits that operate on the Pops module produced by
# the Future parser. # the Future parser.
module Pops module Pops
require 'puppetx/puppetlabs/strings/pops/yard_statement' require 'puppet_x/puppetlabs/strings/pops/yard_statement'
require 'puppetx/puppetlabs/strings/pops/yard_transformer' require 'puppet_x/puppetlabs/strings/pops/yard_transformer'
end end
# This submodule contains bits that interface with the YARD plugin system. # This submodule contains bits that interface with the YARD plugin system.
module YARD module YARD
require 'puppetx/puppetlabs/strings/yard/monkey_patches' require 'puppet_x/puppetlabs/strings/yard/monkey_patches'
require 'puppetx/puppetlabs/strings/yard/parser' require 'puppet_x/puppetlabs/strings/yard/parser'
# This submodule contains code objects which are used to represent relevant # This submodule contains code objects which are used to represent relevant
# aspects of puppet code in YARD's Registry # aspects of puppet code in YARD's Registry
module CodeObjects module CodeObjects
require 'puppetx/puppetlabs/strings/yard/code_objects/puppet_namespace_object' require 'puppet_x/puppetlabs/strings/yard/code_objects/puppet_namespace_object'
require 'puppetx/puppetlabs/strings/yard/code_objects/defined_type_object' require 'puppet_x/puppetlabs/strings/yard/code_objects/defined_type_object'
require 'puppetx/puppetlabs/strings/yard/code_objects/host_class_object' require 'puppet_x/puppetlabs/strings/yard/code_objects/host_class_object'
end end
# This submodule contains handlers which are used to extract relevant data about # This submodule contains handlers which are used to extract relevant data about
# puppet code from the ASTs produced by the Ruby and Puppet parsers # puppet code from the ASTs produced by the Ruby and Puppet parsers
module Handlers module Handlers
# This utility library contains some tools for working with Puppet docstrings # This utility library contains some tools for working with Puppet docstrings
require 'puppetx/puppetlabs/strings/yard/handlers/base' require 'puppet_x/puppetlabs/strings/yard/handlers/base'
require 'puppetx/puppetlabs/strings/yard/handlers/defined_type_handler' require 'puppet_x/puppetlabs/strings/yard/handlers/defined_type_handler'
require 'puppetx/puppetlabs/strings/yard/handlers/host_class_handler' require 'puppet_x/puppetlabs/strings/yard/handlers/host_class_handler'
require 'puppetx/puppetlabs/strings/yard/handlers/puppet_3x_function_handler' require 'puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler'
require 'puppetx/puppetlabs/strings/yard/handlers/puppet_4x_function_handler' require 'puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler'
end end
::YARD::Parser::SourceParser.register_parser_type(:puppet, ::YARD::Parser::SourceParser.register_parser_type(:puppet,
Puppetx::PuppetLabs::Strings::YARD::PuppetParser, PuppetX::PuppetLabs::Strings::YARD::PuppetParser,
['pp']) ['pp'])
::YARD::Handlers::Processor.register_handler_namespace(:puppet, ::YARD::Handlers::Processor.register_handler_namespace(:puppet,
Puppetx::PuppetLabs::Strings::YARD::Handlers) PuppetX::PuppetLabs::Strings::YARD::Handlers)
# FIXME: Might not be the best idea to have the template code on the Ruby # FIXME: Might not be the best idea to have the template code on the Ruby
# LOAD_PATH as the contents of this directory really aren't library code. # LOAD_PATH as the contents of this directory really aren't library code.

View File

@ -1,6 +1,6 @@
require 'puppetx/puppetlabs/strings' require 'puppet_x/puppetlabs/strings'
class Puppetx::PuppetLabs::Strings::Actions class PuppetX::PuppetLabs::Strings::Actions
# Creates a new instance of the Actions class by determining # Creates a new instance of the Actions class by determining
# whether or not debug and backtrace arguments should be sent # whether or not debug and backtrace arguments should be sent

View File

@ -6,7 +6,7 @@ require 'ostruct'
# FIXME: Inhertiting from OpenStruct is a bit of a hack. It allows attributes # 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 # to be declared as needed but in the long run understandibility of the code
# would be improved by having a concrete model. # would be improved by having a concrete model.
class Puppetx::PuppetLabs::Strings::Pops::YARDStatement < OpenStruct class PuppetX::PuppetLabs::Strings::Pops::YARDStatement < OpenStruct
attr_reader :pops_obj, :comments attr_reader :pops_obj, :comments
def initialize(pops_obj) def initialize(pops_obj)

View File

@ -4,7 +4,7 @@
# #
# @note Currently, this class only extracts node, host class and type # @note Currently, this class only extracts node, host class and type
# definitions. # definitions.
class Puppetx::PuppetLabs::Strings::Pops::YARDTransformer class PuppetX::PuppetLabs::Strings::Pops::YARDTransformer
def initialize def initialize
@transform_visitor = Puppet::Pops::Visitor.new(self, 'transform') @transform_visitor = Puppet::Pops::Visitor.new(self, 'transform')
end end
@ -26,7 +26,7 @@ class Puppetx::PuppetLabs::Strings::Pops::YARDTransformer
# Extract comments from type definitions and class definitions. Wrap them # Extract comments from type definitions and class definitions. Wrap them
# into YARDStatement objects that provide an interface for YARD handlers. # into YARDStatement objects that provide an interface for YARD handlers.
def transform_NamedDefinition(o) def transform_NamedDefinition(o)
obj = Puppetx::PuppetLabs::Strings::Pops::YARDStatement.new(o) obj = PuppetX::PuppetLabs::Strings::Pops::YARDStatement.new(o)
obj.parameters = o.parameters.map do |p| obj.parameters = o.parameters.map do |p|
param_tuple = [transform(p)] param_tuple = [transform(p)]
param_tuple << ( p.value.nil? ? nil : transform(p.value) ) param_tuple << ( p.value.nil? ? nil : transform(p.value) )
@ -37,7 +37,7 @@ class Puppetx::PuppetLabs::Strings::Pops::YARDTransformer
# Catch-all visitor. # Catch-all visitor.
def transform_Positioned(o) def transform_Positioned(o)
Puppetx::PuppetLabs::Strings::Pops::YARDStatement.new(o) PuppetX::PuppetLabs::Strings::Pops::YARDStatement.new(o)
end end
# nil in... nil out! # nil in... nil out!

View File

@ -1,4 +1,4 @@
class Puppetx::PuppetLabs::Strings::YARD::CodeObjects::DefinedTypeObject < Puppetx::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject class PuppetX::PuppetLabs::Strings::YARD::CodeObjects::DefinedTypeObject < PuppetX::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject
# A list of parameters attached to this class. # A list of parameters attached to this class.
# @return [Array<Array(String, String)>] # @return [Array<Array(String, String)>]
attr_accessor :parameters attr_accessor :parameters

View File

@ -1,4 +1,4 @@
class Puppetx::PuppetLabs::Strings::YARD::CodeObjects::HostClassObject < Puppetx::PuppetLabs::Strings::YARD::CodeObjects::DefinedTypeObject class PuppetX::PuppetLabs::Strings::YARD::CodeObjects::HostClassObject < PuppetX::PuppetLabs::Strings::YARD::CodeObjects::DefinedTypeObject
# The {HostClassObject} that this class inherits from, if any. # The {HostClassObject} that this class inherits from, if any.
# @return [HostClassObject, Proxy, nil] # @return [HostClassObject, Proxy, nil]
attr_accessor :parent_class attr_accessor :parent_class
@ -6,7 +6,7 @@ class Puppetx::PuppetLabs::Strings::YARD::CodeObjects::HostClassObject < Puppetx
# NOTE: `include_mods` is never used as it makes no sense for Puppet, but # NOTE: `include_mods` is never used as it makes no sense for Puppet, but
# this is called by `YARD::Registry` and it will pass a parameter. # this is called by `YARD::Registry` and it will pass a parameter.
def inheritance_tree(include_mods = false) def inheritance_tree(include_mods = false)
if parent_class.is_a?(Puppetx::PuppetLabs::Strings::YARD::CodeObjects::HostClassObject) if parent_class.is_a?(PuppetX::PuppetLabs::Strings::YARD::CodeObjects::HostClassObject)
# Cool. We got a host class. Return self + parent inheritance tree. # Cool. We got a host class. Return self + parent inheritance tree.
[self] + parent_class.inheritance_tree [self] + parent_class.inheritance_tree
elsif parent_class.is_a?(YARD::CodeObjects::Proxy) elsif parent_class.is_a?(YARD::CodeObjects::Proxy)

View File

@ -1,4 +1,4 @@
class Puppetx::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject < YARD::CodeObjects::NamespaceObject class PuppetX::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject < YARD::CodeObjects::NamespaceObject
# NOTE: `YARD::Registry#resolve` requires a method with this signature to # NOTE: `YARD::Registry#resolve` requires a method with this signature to
# be present on all subclasses of `NamespaceObject`. # be present on all subclasses of `NamespaceObject`.
def inheritance_tree(include_mods = false) def inheritance_tree(include_mods = false)

View File

@ -1,8 +1,8 @@
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
# Easy access to custom code objects from which documentation is generated. # Easy access to custom code objects from which documentation is generated.
include Puppetx::PuppetLabs::Strings::YARD::CodeObjects include PuppetX::PuppetLabs::Strings::YARD::CodeObjects
def self.handles?(statement) def self.handles?(statement)
handlers.any? {|h| h == statement.type} handlers.any? {|h| h == statement.type}

View File

@ -1,4 +1,4 @@
class Puppetx::PuppetLabs::Strings::YARD::Handlers::DefinedTypeHandler < Puppetx::PuppetLabs::Strings::YARD::Handlers:: Base class PuppetX::PuppetLabs::Strings::YARD::Handlers::DefinedTypeHandler < PuppetX::PuppetLabs::Strings::YARD::Handlers:: Base
handles ResourceTypeDefinition handles ResourceTypeDefinition
process do process do

View File

@ -1,4 +1,4 @@
class Puppetx::PuppetLabs::Strings::YARD::Handlers::HostClassHandler < Puppetx::PuppetLabs::Strings::YARD::Handlers::Base class PuppetX::PuppetLabs::Strings::YARD::Handlers::HostClassHandler < PuppetX::PuppetLabs::Strings::YARD::Handlers::Base
handles HostClassDefinition handles HostClassDefinition
process do process do

View File

@ -1,5 +1,5 @@
class Puppetx::PuppetLabs::Strings::YARD::Handlers::Puppet3xFunctionHandler < YARD::Handlers::Ruby::Base class PuppetX::PuppetLabs::Strings::YARD::Handlers::Puppet3xFunctionHandler < YARD::Handlers::Ruby::Base
include Puppetx::PuppetLabs::Strings::YARD::CodeObjects include PuppetX::PuppetLabs::Strings::YARD::CodeObjects
handles method_call(:newfunction) handles method_call(:newfunction)

View File

@ -1,8 +1,8 @@
# Handles `dispatch` calls within a future parser function declaration. For # Handles `dispatch` calls within a future parser function declaration. For
# now, it just treats any docstring as an `@overlaod` tag and attaches the # now, it just treats any docstring as an `@overlaod` tag and attaches the
# overload to the parent function. # overload to the parent function.
class Puppetx::PuppetLabs::Strings::YARD::Handlers::Puppet4xFunctionHandler < YARD::Handlers::Ruby::Base class PuppetX::PuppetLabs::Strings::YARD::Handlers::Puppet4xFunctionHandler < YARD::Handlers::Ruby::Base
include Puppetx::PuppetLabs::Strings::YARD::CodeObjects include PuppetX::PuppetLabs::Strings::YARD::CodeObjects
handles method_call(:dispatch) handles method_call(:dispatch)
@ -19,7 +19,7 @@ class Puppetx::PuppetLabs::Strings::YARD::Handlers::Puppet4xFunctionHandler < YA
end end
class Puppet4xFunctionHandler < YARD::Handlers::Ruby::Base class Puppet4xFunctionHandler < YARD::Handlers::Ruby::Base
include Puppetx::PuppetLabs::Strings::YARD::CodeObjects include PuppetX::PuppetLabs::Strings::YARD::CodeObjects
handles method_call(:create_function) handles method_call(:create_function)

View File

@ -1,10 +1,10 @@
require 'yard' require 'yard'
require 'puppet/pops' require 'puppet/pops'
require 'puppetx/puppetlabs/strings' require 'puppet_x/puppetlabs/strings'
require 'puppetx/puppetlabs/strings//pops/yard_transformer' require 'puppet_x/puppetlabs/strings//pops/yard_transformer'
class Puppetx::PuppetLabs::Strings::YARD::PuppetParser < YARD::Parser::Base class PuppetX::PuppetLabs::Strings::YARD::PuppetParser < YARD::Parser::Base
attr_reader :file, :source attr_reader :file, :source
def initialize(source, filename) def initialize(source, filename)
@ -12,7 +12,7 @@ class Puppetx::PuppetLabs::Strings::YARD::PuppetParser < YARD::Parser::Base
@file = filename @file = filename
@parser = Puppet::Pops::Parser::Parser.new() @parser = Puppet::Pops::Parser::Parser.new()
@transformer = Puppetx::PuppetLabs::Strings::Pops::YARDTransformer.new() @transformer = PuppetX::PuppetLabs::Strings::Pops::YARDTransformer.new()
end end
def parse def parse

View File

@ -5,7 +5,7 @@ require 'mocha'
require 'puppet' require 'puppet'
require 'rspec' require 'rspec'
require 'puppetx/puppetlabs/strings' require 'puppet_x/puppetlabs/strings'
RSpec.configure do |config| RSpec.configure do |config|
config.mock_with :mocha config.mock_with :mocha

View File

@ -1,13 +1,13 @@
require 'spec_helper' require 'spec_helper'
require 'puppetx/puppetlabs/strings/pops/yard_statement' require 'puppet_x/puppetlabs/strings/pops/yard_statement'
describe Puppetx::PuppetLabs::Strings::Pops do describe PuppetX::PuppetLabs::Strings::Pops do
let(:parser) {Puppet::Pops::Parser::Parser.new()} let(:parser) {Puppet::Pops::Parser::Parser.new()}
describe "YARDstatement class" do describe "YARDstatement class" do
let(:manifest) {"#hello world\nclass foo { }"} let(:manifest) {"#hello world\nclass foo { }"}
let(:model) {parser.parse_string(manifest).current.definitions.first} let(:model) {parser.parse_string(manifest).current.definitions.first}
let(:test_statement) {Puppetx::PuppetLabs::Strings::Pops::YARDStatement.new(model)} let(:test_statement) {PuppetX::PuppetLabs::Strings::Pops::YARDStatement.new(model)}
describe "when creating a new instance of YARDStatement" do describe "when creating a new instance of YARDStatement" do
it "should extract comments from the source code" do it "should extract comments from the source code" do
@ -19,13 +19,13 @@ describe Puppetx::PuppetLabs::Strings::Pops do
describe "YARDTransfomer class" do describe "YARDTransfomer class" do
let(:manifest) {"#hello world\nclass foo($bar) { }"} let(:manifest) {"#hello world\nclass foo($bar) { }"}
let(:manifest_default) {"#hello world\nclass foo($bar = 3) { }"} let(:manifest_default) {"#hello world\nclass foo($bar = 3) { }"}
let(:transformer) {Puppetx::PuppetLabs::Strings::Pops::YARDTransformer.new} let(:transformer) {PuppetX::PuppetLabs::Strings::Pops::YARDTransformer.new}
describe "transform method" do describe "transform method" do
it "should perform the correct transformation with parameter defaults" do it "should perform the correct transformation with parameter defaults" do
model = parser.parse_string(manifest_default).current.definitions.first model = parser.parse_string(manifest_default).current.definitions.first
statements = transformer.transform(model) statements = transformer.transform(model)
expect(statements.parameters[0][0].class).to be(Puppetx::PuppetLabs::Strings::Pops::YARDStatement) expect(statements.parameters[0][0].class).to be(PuppetX::PuppetLabs::Strings::Pops::YARDStatement)
end end
it "should perform the correct transofmration without parameter defaults" do it "should perform the correct transofmration without parameter defaults" do

View File

@ -1,9 +1,9 @@
require 'spec_helper' require 'spec_helper'
require 'puppetx/puppetlabs/strings/yard/handlers/defined_type_handler' require 'puppet_x/puppetlabs/strings/yard/handlers/defined_type_handler'
require 'strings_spec/parsing' require 'strings_spec/parsing'
describe Puppetx::PuppetLabs::Strings::YARD::Handlers::DefinedTypeHandler do describe PuppetX::PuppetLabs::Strings::YARD::Handlers::DefinedTypeHandler do
include StringsSpec::Parsing include StringsSpec::Parsing
def the_definedtype() def the_definedtype()

View File

@ -1,8 +1,8 @@
require 'spec_helper' require 'spec_helper'
require 'puppetx/puppetlabs/strings/yard/handlers/host_class_handler' require 'puppet_x/puppetlabs/strings/yard/handlers/host_class_handler'
require 'strings_spec/parsing' require 'strings_spec/parsing'
describe Puppetx::PuppetLabs::Strings::YARD::Handlers::HostClassHandler do describe PuppetX::PuppetLabs::Strings::YARD::Handlers::HostClassHandler do
include StringsSpec::Parsing include StringsSpec::Parsing
def the_hostclass() def the_hostclass()

View File

@ -1,8 +1,8 @@
require 'spec_helper' require 'spec_helper'
require 'puppetx/puppetlabs/strings/yard/handlers/puppet_3x_function_handler' require 'puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler'
require 'strings_spec/parsing' require 'strings_spec/parsing'
describe Puppetx::PuppetLabs::Strings::YARD::Handlers::Puppet3xFunctionHandler do describe PuppetX::PuppetLabs::Strings::YARD::Handlers::Puppet3xFunctionHandler do
include StringsSpec::Parsing include StringsSpec::Parsing
def the_method() def the_method()

View File

@ -1,8 +1,8 @@
require 'spec_helper' require 'spec_helper'
require 'puppetx/puppetlabs/strings/yard/handlers/puppet_4x_function_handler' require 'puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler'
require 'strings_spec/parsing' require 'strings_spec/parsing'
describe Puppetx::PuppetLabs::Strings::YARD::Handlers::Puppet4xFunctionHandler do describe PuppetX::PuppetLabs::Strings::YARD::Handlers::Puppet4xFunctionHandler do
include StringsSpec::Parsing include StringsSpec::Parsing
def the_method() def the_method()