class PuppetStrings::Yard::CodeObjects::DefinedType

Implements the Puppet defined type code object.

Attributes

parameters[R]
statement[R]

Public Class Methods

new(statement) click to toggle source

Initializes a Puppet defined type code object. @param [PuppetStrings::Parsers::DefinedTypeStatement] statement The defined type statement that was parsed. @return [void]

# File lib/puppet-strings/yard/code_objects/defined_type.rb, line 27
def initialize(statement)
  @statement = statement
  @parameters = statement.parameters.map { |p| [p.name, p.value] }
  super(PuppetStrings::Yard::CodeObjects::DefinedTypes.instance, statement.name)
end

Public Instance Methods

source() click to toggle source

Gets the source of the code object. @return Returns the source of the code object.

# File lib/puppet-strings/yard/code_objects/defined_type.rb, line 41
def source
  @statement.source
end
to_hash() click to toggle source

Converts the code object to a hash representation. @return [Hash] Returns a hash representation of the code object.

# File lib/puppet-strings/yard/code_objects/defined_type.rb, line 47
def to_hash
  hash = {}
  hash[:name] = name
  hash[:file] = file
  hash[:line] = line
  hash[:docstring] = PuppetStrings::Json.docstring_to_hash(docstring)
  defaults = Hash[*parameters.select{ |p| !p[1].nil? }.flatten]
  hash[:defaults] = defaults unless defaults.empty?
  hash[:source] = source unless source && source.empty?
  hash
end
type() click to toggle source

Gets the type of the code object. @return Returns the type of the code object.

# File lib/puppet-strings/yard/code_objects/defined_type.rb, line 35
def type
  :puppet_defined_type
end