(PDOC-3) Switch to one line class declarations

Prior to this commit, many of the classes in this project were declared
in two lines. The first line would put them in the context of the module
they belonged to, and the second line would declare the class and deal with
inheritance. In order to make the code more readable and to allow
require statements to be moved to the top level, turn all class declarations
into one line statements.
This commit is contained in:
Hailee Kenney 2014-09-29 15:49:05 -07:00
parent df648a246f
commit f0da72b2b7
13 changed files with 376 additions and 393 deletions

View File

@ -1,5 +1,4 @@
require 'puppet/face' require 'puppet/face'
require 'puppetx/puppetlabs/strings/actions'
Puppet::Face.define(:strings, '0.0.1') do Puppet::Face.define(:strings, '0.0.1') do
summary "Generate Puppet documentation with YARD." summary "Generate Puppet documentation with YARD."
@ -34,6 +33,7 @@ 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'
yardoc_actions = Puppetx::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace]) yardoc_actions = Puppetx::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace])
@ -63,6 +63,7 @@ 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'
server_actions = Puppetx::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace]) server_actions = Puppetx::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace])

View File

@ -6,6 +6,11 @@ module Puppetx::PuppetLabs
# 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
module Handlers
end
module CodeObjects
end
end end
# This submodule contains bits that operate on the Pops module produced by # This submodule contains bits that operate on the Pops module produced by

View File

@ -3,14 +3,13 @@ require 'puppet/pops'
require 'puppetx/puppetlabs/strings' require 'puppetx/puppetlabs/strings'
module Puppetx::PuppetLabs::Strings::Pops # An adapter class that conforms a Pops model instance + adapters to the
# An adapter class that conforms a Pops model instance + adapters to the # interface expected by YARD handlers.
# interface expected by YARD handlers. #
# # 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 YARDStatement < OpenStruct
attr_reader :pops_obj, :comments attr_reader :pops_obj, :comments
def initialize(pops_obj) def initialize(pops_obj)
@ -73,6 +72,4 @@ module Puppetx::PuppetLabs::Strings::Pops
# Stick everything back together. # Stick everything back together.
comments.join comments.join
end end
end
end end

View File

@ -2,14 +2,13 @@ require 'puppet/pops'
require 'puppetx/puppetlabs/strings' require 'puppetx/puppetlabs/strings'
require 'puppetx/puppetlabs/strings/pops/yard_statement' require 'puppetx/puppetlabs/strings/pops/yard_statement'
module Puppetx::PuppetLabs::Strings::Pops # Loosely based on the TreeDumper classes in Pops::Model. The responsibility of
# Loosely based on the TreeDumper classes in Pops::Model. The responsibility of # this class is to walk a Pops::Model and output objects that can be consumed
# this class is to walk a Pops::Model and output objects that can be consumed # by YARD handlers.
# by YARD handlers. #
# # @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 YARDTransformer
def initialize def initialize
@transform_visitor = Puppet::Pops::Visitor.new(self, 'transform') @transform_visitor = Puppet::Pops::Visitor.new(self, 'transform')
end end
@ -31,7 +30,7 @@ module Puppetx::PuppetLabs::Strings::Pops
# 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 = 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) )
@ -42,12 +41,11 @@ module Puppetx::PuppetLabs::Strings::Pops
# Catch-all visitor. # Catch-all visitor.
def transform_Positioned(o) def transform_Positioned(o)
YARDStatement.new(o) Puppetx::PuppetLabs::Strings::Pops::YARDStatement.new(o)
end end
# nil in... nil out! # nil in... nil out!
def transform_NilClass(o) def transform_NilClass(o)
nil nil
end end
end
end end

View File

@ -2,10 +2,8 @@ require 'puppet/pops'
require 'puppetx/puppetlabs/strings/yard/code_objects/puppet_namespace_object' require 'puppetx/puppetlabs/strings/yard/code_objects/puppet_namespace_object'
module Puppetx::PuppetLabs::Strings::YARD::CodeObjects class Puppetx::PuppetLabs::Strings::YARD::CodeObjects::DefinedTypeObject < Puppetx::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject
class DefinedTypeObject < 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
end
end end

View File

@ -1,7 +1,6 @@
require 'puppetx/puppetlabs/strings/yard/code_objects/defined_type_object' require 'puppetx/puppetlabs/strings/yard/code_objects/defined_type_object'
module Puppetx::PuppetLabs::Strings::YARD::CodeObjects class Puppetx::PuppetLabs::Strings::YARD::CodeObjects::HostClassObject < Puppetx::PuppetLabs::Strings::YARD::CodeObjects::DefinedTypeObject
class HostClassObject < 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
@ -9,7 +8,7 @@ module Puppetx::PuppetLabs::Strings::YARD::CodeObjects
# 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?(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)
@ -22,5 +21,4 @@ module Puppetx::PuppetLabs::Strings::YARD::CodeObjects
[self] [self]
end end
end end
end
end end

View File

@ -1,8 +1,7 @@
require 'yard' require 'yard'
require 'puppetx/puppetlabs/strings' require 'puppetx/puppetlabs/strings'
module Puppetx::PuppetLabs::Strings::YARD::CodeObjects class Puppetx::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject < YARD::CodeObjects::NamespaceObject
class 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)
@ -30,6 +29,5 @@ module Puppetx::PuppetLabs::Strings::YARD::CodeObjects
# Unless that namespace is set to a Proxy. # Unless that namespace is set to a Proxy.
# #
# def self.new(namespace, name, *args, &block) # def self.new(namespace, name, *args, &block)
end
end end

View File

@ -4,8 +4,7 @@ require 'puppet/pops'
require 'puppetx/puppetlabs/strings' require 'puppetx/puppetlabs/strings'
require 'puppetx/puppetlabs/strings/yard/code_objects' require 'puppetx/puppetlabs/strings/yard/code_objects'
module Puppetx::PuppetLabs::Strings::YARD::Handlers class Puppetx::PuppetLabs::Strings::YARD::Handlers::Base < YARD::Handlers::Base
class 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.
@ -15,5 +14,4 @@ module Puppetx::PuppetLabs::Strings::YARD::Handlers
handlers.any? {|h| h == statement.type} handlers.any? {|h| h == statement.type}
end end
end
end end

View File

@ -1,7 +1,6 @@
require 'puppetx/puppetlabs/strings/yard/handlers/base' require 'puppetx/puppetlabs/strings/yard/handlers/base'
module Puppetx::PuppetLabs::Strings::YARD::Handlers class Puppetx::PuppetLabs::Strings::YARD::Handlers::DefinedTypeHandler < Puppetx::PuppetLabs::Strings::YARD::Handlers:: Base
class DefinedTypeHandler < Base
handles ResourceTypeDefinition handles ResourceTypeDefinition
process do process do
@ -14,5 +13,4 @@ module Puppetx::PuppetLabs::Strings::YARD::Handlers
register obj register obj
end end
end
end end

View File

@ -1,7 +1,6 @@
require 'puppetx/puppetlabs/strings/yard/handlers/base' require 'puppetx/puppetlabs/strings/yard/handlers/base'
module Puppetx::PuppetLabs::Strings::YARD::Handlers class Puppetx::PuppetLabs::Strings::YARD::Handlers::HostClassHandler < Puppetx::PuppetLabs::Strings::YARD::Handlers::Base
class HostClassHandler < Base
handles HostClassDefinition handles HostClassDefinition
process do process do
@ -20,5 +19,4 @@ module Puppetx::PuppetLabs::Strings::YARD::Handlers
register obj register obj
end end
end
end end

View File

@ -2,8 +2,7 @@
require 'puppet/util/docs' require 'puppet/util/docs'
require 'puppetx/puppetlabs/strings/yard/code_objects' require 'puppetx/puppetlabs/strings/yard/code_objects'
module Puppetx::PuppetLabs::Strings::YARD::Handlers class Puppetx::PuppetLabs::Strings::YARD::Handlers::Puppet3xFunctionHandler < YARD::Handlers::Ruby::Base
class 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)
@ -119,5 +118,4 @@ module Puppetx::PuppetLabs::Strings::YARD::Handlers
# This utility method normalizes indentation and trims whitespace. # This utility method normalizes indentation and trims whitespace.
Puppet::Util::Docs.scrub(source.join) Puppet::Util::Docs.scrub(source.join)
end end
end
end end

View File

@ -1,10 +1,9 @@
require 'puppetx/puppetlabs/strings/yard/code_objects' require 'puppetx/puppetlabs/strings/yard/code_objects'
module Puppetx::PuppetLabs::Strings::YARD::Handlers # 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 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,9 +18,9 @@ module Puppetx::PuppetLabs::Strings::YARD::Handlers
# interested in the @overload tag. # interested in the @overload tag.
owner.add_tag *docstring.tags owner.add_tag *docstring.tags
end end
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)
@ -129,5 +128,4 @@ module Puppetx::PuppetLabs::Strings::YARD::Handlers
# This utility method normalizes indentation and trims whitespace. # This utility method normalizes indentation and trims whitespace.
Puppet::Util::Docs.scrub(source.join) Puppet::Util::Docs.scrub(source.join)
end end
end
end end

View File

@ -4,8 +4,7 @@ require 'puppet/pops'
require 'puppetx/puppetlabs/strings' require 'puppetx/puppetlabs/strings'
require 'puppetx/puppetlabs/strings//pops/yard_transformer' require 'puppetx/puppetlabs/strings//pops/yard_transformer'
module Puppetx::PuppetLabs::Strings::YARD class Puppetx::PuppetLabs::Strings::YARD::PuppetParser < YARD::Parser::Base
class PuppetParser < YARD::Parser::Base
attr_reader :file, :source attr_reader :file, :source
def initialize(source, filename) def initialize(source, filename)
@ -28,5 +27,4 @@ module Puppetx::PuppetLabs::Strings::YARD
Array(statements).compact Array(statements).compact
end end
end
end end