Class: PuppetStrings::Yard::CodeObjects::DataType
- Inherits:
-
Base
- Object
- YARD::CodeObjects::NamespaceObject
- Base
- PuppetStrings::Yard::CodeObjects::DataType
- Defined in:
- lib/puppet-strings/yard/code_objects/data_type.rb
Overview
Implements the Puppet DataType code object.
Instance Method Summary collapse
- #add_function(name, return_type, parameter_types) ⇒ Object
- #add_parameter(name, type, default) ⇒ Object
- #functions ⇒ Object
-
#initialize(name) ⇒ void
constructor
Initializes a Puppet class code object.
- #parameters ⇒ Object
- #set_parameter_default(param_name, default) ⇒ Object
-
#source ⇒ Object
Gets the source of the code object.
-
#to_hash ⇒ Hash
Converts the code object to a hash representation.
-
#type ⇒ Object
Gets the type of the code object.
Methods inherited from Base
Constructor Details
#initialize(name) ⇒ void
Initializes a Puppet class code object.
25 26 27 28 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 25 def initialize(name) super(PuppetStrings::Yard::CodeObjects::DataTypes.instance, name) @defaults = {} end |
Instance Method Details
#add_function(name, return_type, parameter_types) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 63 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 self.meths << meth_obj end |
#add_parameter(name, type, default) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 43 def add_parameter(name, type, default) tag = docstring.(: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 ⇒ Object
77 78 79 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 77 def functions meths end |
#parameters ⇒ Object
59 60 61 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 59 def parameters docstring.(:param).map { |tag| [tag.name, defaults[tag.name]] } end |
#set_parameter_default(param_name, default) ⇒ Object
54 55 56 57 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 54 def set_parameter_default(param_name, default) defaults.delete(param_name) defaults[param_name] = default unless default.nil? end |
#source ⇒ Object
Gets the source of the code object.
38 39 40 41 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 38 def source # Not implemented, but would be nice! nil end |
#to_hash ⇒ Hash
Converts the code object to a hash representation.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 83 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.empty? hash[:source] = source unless source && 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 ⇒ Object
Gets the type of the code object.
32 33 34 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 32 def type :puppet_data_type end |