Sha256: e9d447881b5f3571486a015f9d0a896f2ff1914225702b4eac1a86941dcb18a0

Contents?: true

Size: 1.44 KB

Versions: 37

Compression:

Stored size: 1.44 KB

Contents

require 'puppet/parser/ast'
require 'puppet/parser/ast/branch'
require 'puppet/parser/relationship'

class Puppet::Parser::AST::Relationship < Puppet::Parser::AST::Branch
  RELATIONSHIP_TYPES = %w{-> <- ~> <~}

  attr_accessor :left, :right, :arrow, :type

  def actual_left
    chained? ? left.right : left
  end

  # Evaluate our object, but just return a simple array of the type
  # and name.
  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

  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

  def type
    subscription? ? :subscription : :relationship
  end

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

  private

  def chained?
    left.is_a?(self.class)
  end

  def out_edge?
    ["->", "~>"].include?(arrow)
  end

  def subscription?
    ["~>", "<~"].include?(arrow)
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
puppet-2.6.18 lib/puppet/parser/ast/relationship.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/ast/relationship.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/ast/relationship.rb
puppet-2.6.17 lib/puppet/parser/ast/relationship.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/ast/relationship.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/ast/relationship.rb
puppet-2.6.16 lib/puppet/parser/ast/relationship.rb
puppet-2.6.15 lib/puppet/parser/ast/relationship.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/ast/relationship.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/ast/relationship.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/ast/relationship.rb
puppet-2.7.11 lib/puppet/parser/ast/relationship.rb
puppet-2.6.14 lib/puppet/parser/ast/relationship.rb
supply_drop-0.7.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/ast/relationship.rb
supply_drop-0.6.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/ast/relationship.rb
supply_drop-0.6.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/ast/relationship.rb
puppet-2.6.13 lib/puppet/parser/ast/relationship.rb
puppet-2.7.9 lib/puppet/parser/ast/relationship.rb
puppet-2.7.8 lib/puppet/parser/ast/relationship.rb
puppet-2.7.6 lib/puppet/parser/ast/relationship.rb