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

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

Overview

Implements the Puppet class code object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

new

Constructor Details

#initialize(statement) ⇒ void

Initializes a Puppet class code object.

Parameters:

  • statement (PuppetStrings::Parsers::ClassStatement)

    The class statement that was parsed.



29
30
31
32
33
# File 'lib/puppet-strings/yard/code_objects/class.rb', line 29

def initialize(statement)
  @statement = statement
  @parameters = statement.parameters.map { |p| [p.name, p.value] }
  super(PuppetStrings::Yard::CodeObjects::Classes.instance, statement.name)
end

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters.



24
25
26
# File 'lib/puppet-strings/yard/code_objects/class.rb', line 24

def parameters
  @parameters
end

#statementObject (readonly)

Returns the value of attribute statement.



23
24
25
# File 'lib/puppet-strings/yard/code_objects/class.rb', line 23

def statement
  @statement
end

Instance Method Details

#sourceObject

Gets the source of the code object.

Returns:

  • Returns the source of the code object.



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

def source
  @statement.source
end

#to_hashHash

Converts the code object to a hash representation.

Returns:

  • (Hash)

    Returns a hash representation of the code object.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/puppet-strings/yard/code_objects/class.rb', line 49

def to_hash
  hash = {}
  hash[:name] = name
  hash[:file] = file
  hash[:line] = line
  hash[:inherits] = statement.parent_class if statement.parent_class
  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

#typeObject

Gets the type of the code object.

Returns:

  • Returns the type of the code object.



37
38
39
# File 'lib/puppet-strings/yard/code_objects/class.rb', line 37

def type
  :puppet_class
end