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
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]
# 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
Public Instance Methods
Adds a tag to the overload’s docstring. @param [YARD::Tag] tag The tag to add to the overload’s docstring. @return [void]
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 39 def add_tag(tag) @docstring.add_tag(tag) 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.
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 60 def has_tag?(name) # rubocop:disable Naming/PredicateName @docstring.has_tag?(name) 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.
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 78 def method_missing(method_name, *args, &block) return object.send(method_name, *args, &block) if object.respond_to? method_name super end
Sets the object associated with this tag. @param [Object] value The object to associate with this tag. @return [void]
# 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
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.
# 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
Gets the signature of the overload. @return [String] Returns the signature of the overload.
# 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 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.
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 46 def tag(name) @docstring.tag(name) end
Converts the overload tag to a hash representation. @return [Hash] Returns a hash representation of the overload.
# 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
Gets the type of the object associated with this tag. @return [Symbol] Returns the type of the object associated with this tag.
# File lib/puppet-strings/yard/tags/overload_tag.rb, line 94 def type object.type end