class PuppetStrings::Yard::Tags::OverloadTag
Implements an overload tag for Puppet
functions
This differs from Yard’s overload tag in that the signatures are formatted according to Puppet
language rules.
Attributes
Public Class Methods
Source
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 13 def initialize(name, docstring) super(:overload, nil) @name = name.to_s @parameters = [] @docstring = YARD::Docstring.new(docstring) end
Initializes the overload tag. @param [String, Symbol] name The name of the function being overloaded. @param [String] docstring The docstring for the overload. @return [void]
Public Instance Methods
Source
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 39 def add_tag(tag) @docstring.add_tag(tag) end
Adds a tag to the overload’s docstring. @param [YARD::Tag] tag The tag to add to the overload’s docstring. @return [void]
Source
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 60 def has_tag?(name) # rubocop:disable Naming/PredicateName @docstring.has_tag?(name) end
Determines if a tag with the given name is present. @param [String, Symbol] name The tag name. @return [Boolean] Returns true if there is at least one tag with the given name or false if not.
Source
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 78 def method_missing(method_name, ...) return object.send(method_name, ...) if object.respond_to? method_name super end
Responsible for forwarding method calls to the associated object. @param [Symbol] method_name The method being invoked. @param [Array] args The args passed to the method. @param block The block passed to the method. @return Returns what the method call on the object would return.
Source
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 67 def object=(value) super @docstring.object = value @docstring.tags.each { |tag| tag.object = value } end
Sets the object associated with this tag. @param [Object] value The object to associate with this tag. @return [void]
Source
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 88 def respond_to_missing?(method_name, include_all = false) object.respond_to?(method_name, include_all) || super end
Determines if the associated object responds to the give missing method name. @param [Symbol, String] method_name The name of the method to check. @param [Boolean] include_all True to include all methods in the check or false for only public methods. @return [Boolean] Returns true if the object responds to the method or false if not.
Source
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 22 def signature tags = self.tags(:param) args = @parameters.map do |parameter| name, default = parameter tag = tags.find { |t| t.name == name } if tags type = tag&.types ? "#{tag.type} " : 'Any ' prefix = (name[0]).to_s if name.start_with?('*', '&') name = name[1..] if prefix default = " = #{default}" if default "#{type}#{prefix}$#{name}#{default}" end.join(', ') "#{@name}(#{args})" end
Gets the signature of the overload. @return [String] Returns the signature of the overload.
Source
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 46 def tag(name) @docstring.tag(name) end
Gets the first tag of the given name. @param [String, Symbol] name The name of the tag. @return [YARD::Tag] Returns the first tag if found or nil if not found.
Source
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 100 def to_hash hash = {} hash[:tag_name] = tag_name hash[:text] = text if text hash[:signature] = signature hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) unless docstring.blank? defaults = Hash[*parameters.reject { |p| p[1].nil? }.flatten] hash[:defaults] = defaults unless defaults.empty? hash[:types] = types if types hash[:name] = name if name hash end
Converts the overload tag to a hash representation. @return [Hash] Returns a hash representation of the overload.
Source
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 94 def type object.type end
Gets the type of the object associated with this tag. @return [Symbol] Returns the type of the object associated with this tag.