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



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

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

Instance Attribute Details

#checksObject (readonly)

Returns the value of attribute checks.



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

def checks
  @checks
end

#featuresObject (readonly)

Returns the value of attribute features.



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

def features
  @features
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

Instance Method Details

#add_check(check) ⇒ void

This method returns an undefined value.

Adds a check to the resource type.

Parameters:



145
146
147
148
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 145

def add_check(check)
  @checks ||= []
  @checks << check
end

#add_feature(feature) ⇒ void

This method returns an undefined value.

Adds a feature to the resource type.

Parameters:



137
138
139
140
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 137

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:



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

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:



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

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

#parametersObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 150

def parameters
  # just return params if there are no providers
  return @parameters if providers.empty?

  # return existing params if we have already added provider
  return @parameters if @parameters.any? { |p| p.name == 'provider' }

  provider_param = Parameter.new(
    'provider',
    "The specific backend to use for this `#{self.name.to_s}` resource. You will seldom need " + \
    "to specify this --- Puppet will usually discover the appropriate provider for your platform."
  )

  @parameters << provider_param
end

#providersObject

Not sure if this is where this belongs or if providers should only be resolved at render-time. For now, this should re-resolve on every call. may be able to memoize this



169
170
171
172
173
174
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 169

def providers
  providers = YARD::Registry.all("puppet_providers_#{name}".intern)
  return providers if providers.empty?

  providers.first.children
end

#to_hashHash

Converts the code object to a hash representation.

Returns:

  • (Hash)

    Returns a hash representation of the code object.



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 178

def to_hash
  hash = {}

  hash[:name] = name
  hash[:file] = file
  hash[:line] = line

  hash[:docstring]  = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
  hash[:properties] = properties.sort_by { |p| p.name }.map(&:to_hash) if properties && !properties.empty?
  hash[:parameters] = parameters.sort_by { |p| p.name }.map(&:to_hash) if parameters && !parameters.empty?
  hash[:checks]     = checks.sort_by { |c| c.name }.map(&:to_hash) if checks && !checks.empty?
  hash[:features]   = features.sort_by { |f| f.name }.map(&:to_hash) if features && !features.empty?
  hash[:providers]  = providers.sort_by { |p| p.name }.map(&:to_hash) if providers && !providers.empty?

  hash
end

#typeObject

Gets the type of the code object.

Returns:

  • Returns the type of the code object.



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

def type
  :puppet_type
end