Class: Puppet::Parser::AST::ResourceReference

Inherits:
Branch show all
Defined in:
lib/vendor/puppet/parser/ast/resource_reference.rb

Constant Summary

Constants inherited from Puppet::Parser::AST

AST

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Branch

#children, #pin

Attributes inherited from Puppet::Parser::AST

#file, #line, #parent, #scope

Attributes included from Util::Docs

#doc, #nodoc

Instance Method Summary collapse

Methods inherited from Branch

#each, #initialize

Methods inherited from Puppet::Parser::AST

associates_doc, #evaluate_match, #initialize, #inspect, #parsefail, #parsewrap, #safeevaluate, settor?, #use_docs

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Constructor Details

This class inherits a constructor from Puppet::Parser::AST::Branch

Instance Attribute Details

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/vendor/puppet/parser/ast/resource_reference.rb', line 5

def title
  @title
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/vendor/puppet/parser/ast/resource_reference.rb', line 5

def type
  @type
end

Instance Method Details

#evaluate(scope) ⇒ Object

Evaluate our object, but just return a simple array of the type and name.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/vendor/puppet/parser/ast/resource_reference.rb', line 9

def evaluate(scope)
  titles = Array(title.safeevaluate(scope)).flatten

  a_type, titles = scope.resolve_type_and_titles(type, titles)

  resources = titles.collect{ |a_title|
    Puppet::Resource.new(a_type, a_title)
  }

  return(resources.length == 1 ? resources.pop : resources)
end

#to_sObject



21
22
23
24
25
26
27
# File 'lib/vendor/puppet/parser/ast/resource_reference.rb', line 21

def to_s
  if title.is_a?(Puppet::Parser::AST::ASTArray)
    "#{type.to_s.capitalize}#{title}"
  else
    "#{type.to_s.capitalize}[#{title}]"
  end
end