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_parameter(name, type, default) ⇒ Object
-
#initialize(name) ⇒ void
constructor
Initializes a Puppet class code object.
- #parameter_exist?(name) ⇒ Boolean
- #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 29 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 25 def initialize(name) super(PuppetStrings::Yard::CodeObjects::DataTypes.instance, name) @parameters = [] @defaults = {} end |
Instance Method Details
#add_parameter(name, type, default) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 48 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 |
#parameter_exist?(name) ⇒ Boolean
44 45 46 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 44 def parameter_exist?(name) !docstring.(:param).find { |item| item.name == name }.nil? end |
#parameters ⇒ Object
64 65 66 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 64 def parameters docstring.(:param).map { |tag| [tag.name, defaults[tag.name]] } end |
#set_parameter_default(param_name, default) ⇒ Object
59 60 61 62 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 59 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.
39 40 41 42 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 39 def source # Not implemented, but would be nice! nil end |
#to_hash ⇒ Hash
Converts the code object to a hash representation.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 70 def to_hash hash = {} hash[:name] = name hash[:file] = file hash[:line] = line hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) hash[:defaults] = defaults unless defaults.empty? hash[:source] = source unless source && source.empty? hash end |
#type ⇒ Object
Gets the type of the code object.
33 34 35 |
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 33 def type :puppet_data_type end |