Class: Puppet::Parser::AST::Relationship
- Defined in:
- lib/puppet/parser/ast/relationship.rb
Constant Summary collapse
- RELATIONSHIP_TYPES =
%w{-> <- ~> <~}
Instance Attribute Summary collapse
Attributes inherited from Branch
Instance Method Summary collapse
-
#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
Constructor Details
#initialize(left, right, arrow, args = {}) ⇒ Relationship
Returns a new instance of Relationship.
22 23 24 25 26 27 28 |
# File 'lib/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
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/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/puppet/parser/ast/relationship.rb', line 34 def sides2edge(left, right) out_edge? ? [left, right] : [right, left] end |