Class: PuppetStrings::Yard::CodeObjects::DataType

Inherits:
Base
  • Object
show all
Defined in:
lib/puppet-strings/yard/code_objects/data_type.rb

Overview

Implements the Puppet DataType code object.

Instance Method Summary collapse

Methods inherited from Base

new

Constructor Details

#initialize(name) ⇒ void

Initializes a Puppet class code object.

Parameters:

  • The (String)

    name of the Data Type



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.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

#parameter_exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 44

def parameter_exist?(name)
  !docstring.tags(:param).find { |item| item.name == name }.nil?
end

#parametersObject



64
65
66
# File 'lib/puppet-strings/yard/code_objects/data_type.rb', line 64

def parameters
  docstring.tags(: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

#sourceObject

Gets the source of the code object.

Returns:

  • Returns 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_hashHash

Converts the code object to a hash representation.

Returns:

  • (Hash)

    Returns a hash representation of the code object.



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

#typeObject

Gets the type of the code object.

Returns:

  • Returns 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