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

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

Overview

Implements the Puppet plan code object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

new

Constructor Details

#initialize(statement) ⇒ void

Initializes a Puppet plan code object.

Parameters:

  • statement (PuppetStrings::Parsers::PlanStatement)

    The plan statement that was parsed.



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

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

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

#statementObject (readonly)

Returns the value of attribute statement.



23
24
25
# File 'lib/puppet-strings/yard/code_objects/plan.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.



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

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.



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

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



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

def type
  :puppet_plan
end