Class: PuppetStrings::Yard::CodeObjects::DefinedType

Inherits:
Base
  • Object
show all
Defined in:
lib/puppet-strings/yard/code_objects/defined_type.rb

Overview

Implements the Puppet defined type code object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

new

Constructor Details

#initialize(statement) ⇒ void

Initializes a Puppet defined type code object.

Parameters:

  • statement (PuppetStrings::Parsers::DefinedTypeStatement)

    The defined type statement that was parsed.



27
28
29
30
31
# 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

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters.



22
23
24
# File 'lib/puppet-strings/yard/code_objects/defined_type.rb', line 22

def parameters
  @parameters
end

#statementObject (readonly)

Returns the value of attribute statement.



21
22
23
# File 'lib/puppet-strings/yard/code_objects/defined_type.rb', line 21

def statement
  @statement
end

Instance Method Details

#sourceObject

Gets the source of the code object.

Returns:

  • Returns the source of the code object.



41
42
43
# File 'lib/puppet-strings/yard/code_objects/defined_type.rb', line 41

def source
  @statement.source
end

#to_hashHash

Converts the code object to a hash representation.

Returns:

  • (Hash)

    Returns a hash representation of the code object.



47
48
49
50
51
52
53
54
55
56
57
# 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::Yard::Util.docstring_to_hash(docstring)
  defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
  hash[:defaults] = defaults unless defaults.empty?
  hash[:source] = source unless source && source.empty?
  hash
end

#typeObject

Gets the type of the code object.

Returns:

  • Returns the type of the code object.



35
36
37
# File 'lib/puppet-strings/yard/code_objects/defined_type.rb', line 35

def type
  :puppet_defined_type
end