Class: Puppet::Parser::AST::Relationship

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

Constant Summary collapse

RELATIONSHIP_TYPES =
%w{-> <- ~> <~}

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

Methods inherited from Puppet::Parser::AST

associates_doc, #evaluate_match, #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

#initialize(left, right, arrow, args = {}) ⇒ Relationship

Returns a new instance of Relationship.



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

def initialize(left, right, arrow, args = {})
  super(args)
  unless RELATIONSHIP_TYPES.include?(arrow)
    raise ArgumentError, "Invalid relationship type #{arrow.inspect}; valid types are #{RELATIONSHIP_TYPES.collect { |r| r.to_s }.join(", ")}"
  end
  @left, @right, @arrow = left, right, arrow
end

Instance Attribute Details

#arrowObject

Returns the value of attribute arrow.



8
9
10
# File 'lib/vendor/puppet/parser/ast/relationship.rb', line 8

def arrow
  @arrow
end

#leftObject

Returns the value of attribute left.



8
9
10
# File 'lib/vendor/puppet/parser/ast/relationship.rb', line 8

def left
  @left
end

#rightObject

Returns the value of attribute right.



8
9
10
# File 'lib/vendor/puppet/parser/ast/relationship.rb', line 8

def right
  @right
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/vendor/puppet/parser/ast/relationship.rb', line 8

def type
  @type
end

Instance Method Details

#evaluate(scope) ⇒ Object

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



12
13
14
15
16
17
18
19
20
# File 'lib/vendor/puppet/parser/ast/relationship.rb', line 12

def evaluate(scope)
  real_left = left.safeevaluate(scope)
  real_right = right.safeevaluate(scope)

  source, target = sides2edge(real_left, real_right)
  scope.compiler.add_relationship Puppet::Parser::Relationship.new(source, target, type)

  real_right
end

#sides2edge(left, right) ⇒ Object



34
35
36
# File 'lib/vendor/puppet/parser/ast/relationship.rb', line 34

def sides2edge(left, right)
  out_edge? ? [left, right] : [right, left]
end