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.



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

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

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



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

def features
  @features
end

#parametersObject (readonly)

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

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:



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

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:



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

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:



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

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.



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

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.



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

def type
  :puppet_type
end