Class: PuppetStrings::Yard::CodeObjects::Type

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

Overview

Implements the Puppet resource type code object.

Defined Under Namespace

Classes: Feature, Parameter, Property

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

new

Constructor Details

#initialize(name) ⇒ void

Initializes a new resource type.

Parameters:

  • name (String)

    The resource type name.



102
103
104
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 102

def initialize(name)
  super(PuppetStrings::Yard::CodeObjects::Types.instance, name)
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



97
98
99
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 97

def features
  @features
end

#parametersObject (readonly)

Returns the value of attribute parameters.



97
98
99
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 97

def parameters
  @parameters
end

#propertiesObject (readonly)

Returns the value of attribute properties.



97
98
99
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 97

def properties
  @properties
end

Instance Method Details

#add_feature(feature) ⇒ void

This method returns an undefined value.

Adds a feature to the resource type.

Parameters:



131
132
133
134
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 131

def add_feature(feature)
  @features ||= []
  @features << feature
end

#add_parameter(parameter) ⇒ void

This method returns an undefined value.

Adds a parameter to the resource type

Parameters:



115
116
117
118
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 115

def add_parameter(parameter)
  @parameters ||= []
  @parameters << parameter
end

#add_property(property) ⇒ void

This method returns an undefined value.

Adds a property to the resource type

Parameters:



123
124
125
126
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 123

def add_property(property)
  @properties ||= []
  @properties << property
end

#to_hashHash

Converts the code object to a hash representation.

Returns:

  • (Hash)

    Returns a hash representation of the code object.



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 138

def to_hash
  hash = {}
  hash[:name] = name
  hash[:file] = file
  hash[:line] = line
  hash[:docstring] = PuppetStrings::Json.docstring_to_hash(docstring)
  hash[:properties] = properties.map(&:to_hash) if properties && !properties.empty?
  hash[:parameters] = parameters.map(&:to_hash) if parameters && !parameters.empty?
  hash[:features] = features.map(&:to_hash) if features && !features.empty?
  hash
end

#typeObject

Gets the type of the code object.

Returns:

  • Returns the type of the code object.



108
109
110
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 108

def type
  :puppet_type
end