Class: PuppetStrings::Yard::Tags::OverloadTag
- Inherits:
-
YARD::Tags::Tag
- Object
- YARD::Tags::Tag
- PuppetStrings::Yard::Tags::OverloadTag
- Defined in:
- lib/puppet-strings/yard/tags/overload_tag.rb
Overview
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.
Instance Attribute Summary collapse
-
#docstring ⇒ Object
readonly
Returns the value of attribute docstring.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
-
#add_tag(tag) ⇒ void
Adds a tag to the overload’s docstring.
-
#has_tag?(name) ⇒ Boolean
Determines if a tag with the given name is present.
-
#initialize(name, docstring) ⇒ void
constructor
Initializes the overload tag.
-
#method_missing(method_name) ⇒ Object
Responsible for forwarding method calls to the associated object.
-
#object=(value) ⇒ void
Sets the object associated with this tag.
-
#respond_to_missing?(method_name, include_all = false) ⇒ Boolean
Determines if the associated object responds to the give missing method name.
-
#signature ⇒ String
Gets the signature of the overload.
-
#tag(name) ⇒ YARD::Tag
Gets the first tag of the given name.
-
#tags(name = nil) ⇒ Array<Yard::Tag>
Gets all tags or tags of a given name.
-
#to_hash ⇒ Hash
Converts the overload tag to a hash representation.
-
#type ⇒ Symbol
Gets the type of the object associated with this tag.
Constructor Details
#initialize(name, docstring) ⇒ void
Initializes the overload tag.
13 14 15 16 17 18 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
Responsible for forwarding method calls to the associated object.
78 79 80 81 82 |
# 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 |
Instance Attribute Details
#docstring ⇒ Object (readonly)
Returns the value of attribute docstring.
7 8 9 |
# File 'lib/puppet-strings/yard/tags/overload_tag.rb', line 7 def docstring @docstring end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
7 8 9 |
# File 'lib/puppet-strings/yard/tags/overload_tag.rb', line 7 def parameters @parameters end |
Instance Method Details
#add_tag(tag) ⇒ void
This method returns an undefined value.
Adds a tag to the overload’s docstring.
39 40 41 |
# File 'lib/puppet-strings/yard/tags/overload_tag.rb', line 39 def add_tag(tag) @docstring.add_tag(tag) end |
#has_tag?(name) ⇒ Boolean
Determines if a tag with the given name is present.
60 61 62 |
# File 'lib/puppet-strings/yard/tags/overload_tag.rb', line 60 def has_tag?(name) # rubocop:disable Naming/PredicateName @docstring.has_tag?(name) end |
#object=(value) ⇒ void
This method returns an undefined value.
Sets the object associated with this tag.
67 68 69 70 71 |
# File 'lib/puppet-strings/yard/tags/overload_tag.rb', line 67 def object=(value) super @docstring.object = value @docstring..each { |tag| tag.object = value } end |
#respond_to_missing?(method_name, include_all = false) ⇒ Boolean
Determines if the associated object responds to the give missing method name.
88 89 90 |
# 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 |
#signature ⇒ String
Gets the signature of the overload.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/puppet-strings/yard/tags/overload_tag.rb', line 22 def signature = self.(:param) args = @parameters.map do |parameter| name, default = parameter tag = .find { |t| t.name == name } if 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 |
#tag(name) ⇒ YARD::Tag
Gets the first tag of the given name.
46 47 48 |
# File 'lib/puppet-strings/yard/tags/overload_tag.rb', line 46 def tag(name) @docstring.tag(name) end |
#tags(name = nil) ⇒ Array<Yard::Tag>
Gets all tags or tags of a given name.
53 54 55 |
# File 'lib/puppet-strings/yard/tags/overload_tag.rb', line 53 def (name = nil) @docstring.(name) end |
#to_hash ⇒ Hash
Converts the overload tag to a hash representation.
100 101 102 103 104 105 106 107 108 109 110 111 |
# 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 |
#type ⇒ Symbol
Gets the type of the object associated with this tag.
94 95 96 |
# File 'lib/puppet-strings/yard/tags/overload_tag.rb', line 94 def type object.type end |