class PuppetStrings::Yard::CodeObjects::Type
Implements the Puppet
resource type code object.
Attributes
Public Class Methods
Initializes a new resource type. @param [String] name The resource type name. @return [void]
PuppetStrings::Yard::CodeObjects::Base::new
# File lib/puppet-strings/yard/code_objects/type.rb, line 108 def initialize(name) super(PuppetStrings::Yard::CodeObjects::Types.instance, name) end
Public Instance Methods
Adds a check to the resource type. @param [PuppetStrings::Yard::CodeObjects::Type::Check] check The check to add. @return [void]
# File lib/puppet-strings/yard/code_objects/type.rb, line 145 def add_check(check) @checks ||= [] @checks << check end
Adds a feature to the resource type. @param [PuppetStrings::Yard::CodeObjects::Type::Feature] feature The feature to add. @return [void]
# File lib/puppet-strings/yard/code_objects/type.rb, line 137 def add_feature(feature) @features ||= [] @features << feature end
Adds a parameter to the resource type @param [PuppetStrings::Yard::CodeObjects::Type::Parameter] parameter The parameter to add. @return [void]
# File lib/puppet-strings/yard/code_objects/type.rb, line 121 def add_parameter(parameter) @parameters ||= [] @parameters << parameter end
Adds a property to the resource type @param [PuppetStrings::Yard::CodeObjects::Type::Property] property The property to add. @return [void]
# File lib/puppet-strings/yard/code_objects/type.rb, line 129 def add_property(property) @properties ||= [] @properties << property end
# File lib/puppet-strings/yard/code_objects/type.rb, line 150 def parameters @parameters ||= [] # guard against not filled 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 `#{name}` resource. You will seldom need " \ 'to specify this --- Puppet will usually discover the appropriate provider for your platform.' ) @parameters ||= [] @parameters << provider_param end
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
# File lib/puppet-strings/yard/code_objects/type.rb, line 171 def providers providers = YARD::Registry.all(:"puppet_providers_#{name}") return providers if providers.empty? providers.first.children end
Converts the code object to a hash representation. @return [Hash] Returns a hash representation of the code object.
# File lib/puppet-strings/yard/code_objects/type.rb, line 180 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(&:name).map(&:to_hash) if properties && !properties.empty? hash[:parameters] = parameters.sort_by(&:name).map(&:to_hash) if parameters && !parameters.empty? hash[:checks] = checks.sort_by(&:name).map(&:to_hash) if checks && !checks.empty? hash[:features] = features.sort_by(&:name).map(&:to_hash) if features && !features.empty? hash[:providers] = providers.sort_by(&:name).map(&:to_hash) if providers && !providers.empty? hash end
Gets the type of the code object. @return Returns the type of the code object.
# File lib/puppet-strings/yard/code_objects/type.rb, line 114 def type :puppet_type end