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

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

Overview

Represents a resource type parameter.

Direct Known Subclasses

Property

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, docstring = nil) ⇒ Parameter

Initializes a resource type parameter or property.

Parameters:

  • name (String)

    The name of the parameter or property.

  • docstring (String) (defaults to: nil)

    The docstring for the parameter or property.s



30
31
32
33
34
35
36
37
38
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 30

def initialize(name, docstring = nil)
  @name = name
  @docstring = docstring || ''
  @values = []
  @data_type = []
  @aliases = {}
  @isnamevar = false
  @default = nil
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



24
25
26
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 24

def aliases
  @aliases
end

#data_typeObject

Returns the value of attribute data_type.



25
26
27
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 25

def data_type
  @data_type
end

#defaultObject

Returns the value of attribute default.



25
26
27
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 25

def default
  @default
end

#docstringObject

Returns the value of attribute docstring.



25
26
27
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 25

def docstring
  @docstring
end

#isnamevarObject

Returns the value of attribute isnamevar.



25
26
27
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 25

def isnamevar
  @isnamevar
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 24

def name
  @name
end

#required_featuresObject

Returns the value of attribute required_features.



25
26
27
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 25

def required_features
  @required_features
end

#valuesObject (readonly)

Returns the value of attribute values.



24
25
26
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 24

def values
  @values
end

Instance Method Details

#add(value) ⇒ void

This method returns an undefined value.

Adds a value to the parameter or property.

Parameters:

  • value (String)

    The value to add.



43
44
45
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 43

def add(value)
  @values << value
end

#alias(new, old) ⇒ void

This method returns an undefined value.

Aliases a value to another value.

Parameters:

  • new (String)

    The new (alias) value.

  • old (String)

    The old (existing) value.



51
52
53
54
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 51

def alias(new, old)
  @values << new unless @values.include? new
  @aliases[new] = old
end

#to_hashHash

Converts the parameter to a hash representation.

Returns:

  • (Hash)

    Returns a hash representation of the parameter.



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 58

def to_hash
  hash = {}
  hash[:name] = name
  hash[:description] = docstring unless docstring.empty?
  hash[:values] = values unless values.empty?
  hash[:data_type] = data_type unless data_type.empty?
  hash[:aliases] = aliases unless aliases.empty?
  hash[:isnamevar] = true if isnamevar
  hash[:required_features] = required_features if required_features
  hash[:default] = default if default
  hash
end