Sha256: ed960cd16b320555d1446da820d95a825f72f49971e37f768f09a965846b2994

Contents?: true

Size: 1.9 KB

Versions: 8

Compression:

Stored size: 1.9 KB

Contents

require 'puppet-strings/yard/code_objects/group'

# Implements the group for Puppet defined types.
class PuppetStrings::Yard::CodeObjects::DefinedTypes < PuppetStrings::Yard::CodeObjects::Group
  # Gets the singleton instance of the group.
  # @return Returns the singleton instance of the group.
  def self.instance
    super(:puppet_defined_types)
  end

  # Gets the display name of the group.
  # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
  # @return [String] Returns the display name of the group.
  def name(prefix = false)
    'Defined Types'
  end
end

# Implements the Puppet defined type code object.
class PuppetStrings::Yard::CodeObjects::DefinedType < PuppetStrings::Yard::CodeObjects::Base
  attr_reader :statement
  attr_reader :parameters

  # Initializes a Puppet defined type code object.
  # @param [PuppetStrings::Parsers::DefinedTypeStatement] statement The defined type statement that was parsed.
  # @return [void]
  def initialize(statement)
    @statement = statement
    @parameters = statement.parameters.map { |p| [p.name, p.value] }
    super(PuppetStrings::Yard::CodeObjects::DefinedTypes.instance, statement.name)
  end

  # Gets the type of the code object.
  # @return Returns the type of the code object.
  def type
    :puppet_defined_type
  end

  # Gets the source of the code object.
  # @return Returns the source of the code object.
  def source
    @statement.source
  end

  # Converts the code object to a hash representation.
  # @return [Hash] Returns a hash representation of the code object.
  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
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puppet-strings-2.1.0 lib/puppet-strings/yard/code_objects/defined_type.rb
puppet-strings-2.0.0 lib/puppet-strings/yard/code_objects/defined_type.rb
puppet-strings-1.2.1 lib/puppet-strings/yard/code_objects/defined_type.rb
puppet-strings-1.2.0 lib/puppet-strings/yard/code_objects/defined_type.rb
puppet-strings-1.1.1 lib/puppet-strings/yard/code_objects/defined_type.rb
puppet-strings-1.1.0 lib/puppet-strings/yard/code_objects/defined_type.rb
puppet-strings-1.0.0 lib/puppet-strings/yard/code_objects/defined_type.rb
puppet-strings-0.99.0 lib/puppet-strings/yard/code_objects/defined_type.rb