(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 'puppetx/puppetlabs/strings/actions'
Puppet::Face.define(:strings, '0.0.1') do
summary "Generate Puppet documentation with YARD."
@ -34,6 +33,7 @@ Puppet::Face.define(:strings, '0.0.1') do
when_invoked do |*args|
check_required_features
require 'puppetx/puppetlabs/strings/actions'
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|
check_required_features
require 'puppetx/puppetlabs/strings/actions'
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.
module YARD
module Handlers
end
module CodeObjects
end
end
# 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'
module Puppetx::PuppetLabs::Strings::Pops
# An adapter class that conforms a Pops model instance + adapters to the
# interface expected by YARD handlers.
#
# 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
# would be improved by having a concrete model.
class YARDStatement < OpenStruct
# An adapter class that conforms a Pops model instance + adapters to the
# interface expected by YARD handlers.
#
# 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
# would be improved by having a concrete model.
class Puppetx::PuppetLabs::Strings::Pops::YARDStatement < OpenStruct
attr_reader :pops_obj, :comments
def initialize(pops_obj)
@ -73,6 +72,4 @@ module Puppetx::PuppetLabs::Strings::Pops
# Stick everything back together.
comments.join
end
end
end

View File

@ -2,14 +2,13 @@ require 'puppet/pops'
require 'puppetx/puppetlabs/strings'
require 'puppetx/puppetlabs/strings/pops/yard_statement'
module Puppetx::PuppetLabs::Strings::Pops
# 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
# by YARD handlers.
#
# @note Currently, this class only extracts node, host class and type
# definitions.
class YARDTransformer
# 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
# by YARD handlers.
#
# @note Currently, this class only extracts node, host class and type
# definitions.
class Puppetx::PuppetLabs::Strings::Pops::YARDTransformer
def initialize
@transform_visitor = Puppet::Pops::Visitor.new(self, 'transform')
end
@ -31,7 +30,7 @@ module Puppetx::PuppetLabs::Strings::Pops
# Extract comments from type definitions and class definitions. Wrap them
# into YARDStatement objects that provide an interface for YARD handlers.
def transform_NamedDefinition(o)
obj = YARDStatement.new(o)
obj = Puppetx::PuppetLabs::Strings::Pops::YARDStatement.new(o)
obj.parameters = o.parameters.map do |p|
param_tuple = [transform(p)]
param_tuple << ( p.value.nil? ? nil : transform(p.value) )
@ -42,12 +41,11 @@ module Puppetx::PuppetLabs::Strings::Pops
# Catch-all visitor.
def transform_Positioned(o)
YARDStatement.new(o)
Puppetx::PuppetLabs::Strings::Pops::YARDStatement.new(o)
end
# nil in... nil out!
def transform_NilClass(o)
nil
end
end
end

View File

@ -2,10 +2,8 @@ require 'puppet/pops'
require 'puppetx/puppetlabs/strings/yard/code_objects/puppet_namespace_object'
module Puppetx::PuppetLabs::Strings::YARD::CodeObjects
class DefinedTypeObject < PuppetNamespaceObject
class Puppetx::PuppetLabs::Strings::YARD::CodeObjects::DefinedTypeObject < Puppetx::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject
# A list of parameters attached to this class.
# @return [Array<Array(String, String)>]
attr_accessor :parameters
end
end

View File

@ -1,7 +1,6 @@
require 'puppetx/puppetlabs/strings/yard/code_objects/defined_type_object'
module Puppetx::PuppetLabs::Strings::YARD::CodeObjects
class HostClassObject < DefinedTypeObject
class Puppetx::PuppetLabs::Strings::YARD::CodeObjects::HostClassObject < Puppetx::PuppetLabs::Strings::YARD::CodeObjects::DefinedTypeObject
# The {HostClassObject} that this class inherits from, if any.
# @return [HostClassObject, Proxy, nil]
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
# this is called by `YARD::Registry` and it will pass a parameter.
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.
[self] + parent_class.inheritance_tree
elsif parent_class.is_a?(YARD::CodeObjects::Proxy)
@ -22,5 +21,4 @@ module Puppetx::PuppetLabs::Strings::YARD::CodeObjects
[self]
end
end
end
end

View File

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

View File

@ -4,8 +4,7 @@ require 'puppet/pops'
require 'puppetx/puppetlabs/strings'
require 'puppetx/puppetlabs/strings/yard/code_objects'
module Puppetx::PuppetLabs::Strings::YARD::Handlers
class Base < YARD::Handlers::Base
class Puppetx::PuppetLabs::Strings::YARD::Handlers::Base < YARD::Handlers::Base
# Easy access to Pops model objects for handler matching.
include Puppet::Pops::Model
# 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}
end
end
end

View File

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

View File

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

View File

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

View File

@ -1,10 +1,9 @@
require 'puppetx/puppetlabs/strings/yard/code_objects'
module Puppetx::PuppetLabs::Strings::YARD::Handlers
# Handles `dispatch` calls within a future parser function declaration. For
# now, it just treats any docstring as an `@overlaod` tag and attaches the
# overload to the parent function.
class Puppet4xFunctionHandler < YARD::Handlers::Ruby::Base
# Handles `dispatch` calls within a future parser function declaration. For
# now, it just treats any docstring as an `@overlaod` tag and attaches the
# overload to the parent function.
class Puppetx::PuppetLabs::Strings::YARD::Handlers::Puppet4xFunctionHandler < YARD::Handlers::Ruby::Base
include Puppetx::PuppetLabs::Strings::YARD::CodeObjects
handles method_call(:dispatch)
@ -19,9 +18,9 @@ module Puppetx::PuppetLabs::Strings::YARD::Handlers
# interested in the @overload tag.
owner.add_tag *docstring.tags
end
end
end
class Puppet4xFunctionHandler < YARD::Handlers::Ruby::Base
class Puppet4xFunctionHandler < YARD::Handlers::Ruby::Base
include Puppetx::PuppetLabs::Strings::YARD::CodeObjects
handles method_call(:create_function)
@ -129,5 +128,4 @@ module Puppetx::PuppetLabs::Strings::YARD::Handlers
# This utility method normalizes indentation and trims whitespace.
Puppet::Util::Docs.scrub(source.join)
end
end
end

View File

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