class PuppetStrings::Yard::CodeObjects::DataType
Public Class Methods
new(name)
click to toggle source
Initializes a Puppet
class code object. @param [String] The name of the Data Type @return [void]
Calls superclass method
PuppetStrings::Yard::CodeObjects::Base::new
# File lib/puppet-strings/yard/code_objects/data_type.rb, line 27 def initialize(name) super(PuppetStrings::Yard::CodeObjects::DataTypes.instance, name) @defaults = {} end
Public Instance Methods
add_function(name, return_type, parameter_types)
click to toggle source
# File lib/puppet-strings/yard/code_objects/data_type.rb, line 65 def add_function(name, return_type, parameter_types) meth_obj = YARD::CodeObjects::MethodObject.new(self, name, :class) # Add return tag meth_obj.add_tag(YARD::Tags::Tag.new(:return, '', return_type)) # Add parameters parameter_types.each_with_index do |param_type, index| meth_obj.add_tag(YARD::Tags::Tag.new(:param, '', [param_type], "param#{index + 1}")) end meths << meth_obj end
add_parameter(name, type, default)
click to toggle source
# File lib/puppet-strings/yard/code_objects/data_type.rb, line 45 def add_parameter(name, type, default) tag = docstring.tags(:param).find { |item| item.name == name } if tag.nil? tag = YARD::Tags::Tag.new(:param, '', nil, name) docstring.add_tag(tag) end type = [type] unless type.is_a?(Array) tag.types = type if tag.types.nil? set_parameter_default(name, default) end
functions()
click to toggle source
# File lib/puppet-strings/yard/code_objects/data_type.rb, line 79 def functions meths end
parameters()
click to toggle source
# File lib/puppet-strings/yard/code_objects/data_type.rb, line 61 def parameters docstring.tags(:param).map { |tag| [tag.name, defaults[tag.name]] } end
set_parameter_default(param_name, default)
click to toggle source
# File lib/puppet-strings/yard/code_objects/data_type.rb, line 56 def set_parameter_default(param_name, default) defaults.delete(param_name) defaults[param_name] = default unless default.nil? end
source()
click to toggle source
Gets the source of the code object. @return Returns the source of the code object.
# File lib/puppet-strings/yard/code_objects/data_type.rb, line 40 def source # Not implemented, but would be nice! nil end
to_hash()
click to toggle source
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/data_type.rb, line 85 def to_hash hash = {} hash[:name] = name hash[:file] = file hash[:line] = line hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example]) hash[:defaults] = defaults unless defaults.nil? || defaults.empty? hash[:source] = source unless source.nil? || source.empty? hash[:functions] = functions.map do |func| { name: func.name, signature: func.signature, docstring: PuppetStrings::Yard::Util.docstring_to_hash(func.docstring, %i[param option enum return example]) } end hash end
type()
click to toggle source
Gets the type of the code object. @return Returns the type of the code object.
# File lib/puppet-strings/yard/code_objects/data_type.rb, line 34 def type :puppet_data_type end