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

Check, 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



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

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.



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

def aliases
  @aliases
end

#data_typeObject

Returns the value of attribute data_type.



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

def data_type
  @data_type
end

#defaultObject

Returns the value of attribute default.



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

def default
  @default
end

#docstringObject

Returns the value of attribute docstring.



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

def docstring
  @docstring
end

#isnamevarObject

Returns the value of attribute isnamevar.



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

def isnamevar
  @isnamevar
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#required_featuresObject

Returns the value of attribute required_features.



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

def required_features
  @required_features
end

#valuesObject (readonly)

Returns the value of attribute values.



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

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.



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

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.



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

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.



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

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