Class: Puppet::Parser::AST::Relationship
- Inherits:
-
Branch
- Object
- Puppet::Parser::AST
- Branch
- Puppet::Parser::AST::Relationship
- Defined in:
- lib/puppet/parser/ast/relationship.rb
Constant Summary collapse
- RELATIONSHIP_TYPES =
%w{-> <- ~> <~}
Constants inherited from Puppet::Parser::AST
Instance Attribute Summary collapse
-
#arrow ⇒ Object
Returns the value of attribute arrow.
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Branch
Attributes inherited from Puppet::Parser::AST
Attributes included from Util::Docs
Attributes included from FileCollection::Lookup
Instance Method Summary collapse
- #actual_left ⇒ Object
-
#evaluate(scope) ⇒ Object
Evaluate our object, but just return a simple array of the type and name.
-
#initialize(left, right, arrow, args = {}) ⇒ Relationship
constructor
A new instance of Relationship.
- #sides2edge(left, right) ⇒ Object
Methods inherited from Branch
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, #nodoc?, #pad, scrub
Methods included from Util::MethodHelper
#requiredopts, #set_options, #symbolize_options
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail
Methods included from FileCollection::Lookup
#file, #file=, #file_collection
Constructor Details
#initialize(left, right, arrow, args = {}) ⇒ Relationship
Returns a new instance of Relationship.
31 32 33 34 35 36 37 |
# File 'lib/puppet/parser/ast/relationship.rb', line 31 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
#arrow ⇒ Object
Returns the value of attribute arrow.
8 9 10 |
# File 'lib/puppet/parser/ast/relationship.rb', line 8 def arrow @arrow end |
#left ⇒ Object
Returns the value of attribute left.
8 9 10 |
# File 'lib/puppet/parser/ast/relationship.rb', line 8 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
8 9 10 |
# File 'lib/puppet/parser/ast/relationship.rb', line 8 def right @right end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/puppet/parser/ast/relationship.rb', line 8 def type @type end |
Instance Method Details
#actual_left ⇒ Object
10 11 12 |
# File 'lib/puppet/parser/ast/relationship.rb', line 10 def actual_left chained? ? left.right : left end |
#evaluate(scope) ⇒ Object
Evaluate our object, but just return a simple array of the type and name.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/puppet/parser/ast/relationship.rb', line 16 def evaluate(scope) if chained? real_left = left.safeevaluate(scope) left_dep = left_dep.shift if left_dep.is_a?(Array) else real_left = left.safeevaluate(scope) end real_right = right.safeevaluate(scope) source, target = sides2edge(real_left, real_right) result = Puppet::Parser::Relationship.new(source, target, type) scope.compiler.add_relationship(result) real_right end |
#sides2edge(left, right) ⇒ Object
43 44 45 |
# File 'lib/puppet/parser/ast/relationship.rb', line 43 def sides2edge(left, right) out_edge? ? [left, right] : [right, left] end |