class PuppetStrings::Yard::CodeObjects::Function
Implements the Puppet
function code object.
Constants
- PUPPET
-
Identifier for
Puppet
language functions - RUBY_3X
-
Identifier for 3.x Ruby API functions
- RUBY_4X
-
Identifier for 4.x Ruby API functions
Attributes
Public Class Methods
Source
# File lib/puppet-strings/yard/code_objects/function.rb, line 37 def initialize(name, function_type) super(PuppetStrings::Yard::CodeObjects::Functions.instance(function_type), name) @parameters = [] @function_type = function_type end
Initializes a Puppet
function code object. @param [String] name The name of the function. @param [Symbol] function_type
The type of function (e.g. :ruby3x, :ruby4x, :puppet) @return [void]
PuppetStrings::Yard::CodeObjects::Base::new
Public Instance Methods
Source
# File lib/puppet-strings/yard/code_objects/function.rb, line 51 def function_type case @function_type when RUBY_3X 'Ruby 3.x API' when RUBY_4X 'Ruby 4.x API' else 'Puppet Language' end end
Gets the function type display string. @return Returns the function type display string.
Source
# File lib/puppet-strings/yard/code_objects/function.rb, line 64 def signature return '' if has_tag? :overload 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 Puppet
signature of the function (single overload only). @return [String] Returns the Puppet
signature of the function.
Source
# File lib/puppet-strings/yard/code_objects/function.rb, line 82 def to_hash hash = {} hash[:name] = name hash[:file] = file hash[:line] = line hash[:type] = @function_type.to_s hash[:signatures] = [] if has_tag? :overload # loop over overloads and append onto the signatures array tags(:overload).each do |o| hash[:signatures] << { signature: o.signature, docstring: PuppetStrings::Yard::Util.docstring_to_hash(o.docstring, %i[param option enum return example]) } end else hash[:signatures] << { signature:, docstring: PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example]) } end hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) defaults = Hash[*parameters.reject { |p| p[1].nil? }.flatten] hash[:defaults] = defaults unless defaults.nil? || defaults.empty? hash[:source] = source unless source.nil? || source.empty? hash end
Converts the code object to a hash representation. @return [Hash] Returns a hash representation of the code object.
Source
# File lib/puppet-strings/yard/code_objects/function.rb, line 45 def type :puppet_function end
Gets the type of the code object. @return Returns the type of the code object.