Sha256: ba3b315f375e8b740771d715bda9f3538f9939b9c3fc1562338faba2da2464b6

Contents?: true

Size: 1.18 KB

Versions: 133

Compression:

Stored size: 1.18 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

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

  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 out_edge?
    ["->", "~>"].include?(arrow)
  end

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

Version data entries

133 entries across 133 versions & 4 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/relationship.rb
puppet-3.8.7 lib/puppet/parser/ast/relationship.rb
puppet-3.8.7-x86-mingw32 lib/puppet/parser/ast/relationship.rb
puppet-3.8.7-x64-mingw32 lib/puppet/parser/ast/relationship.rb
puppet-3.8.6 lib/puppet/parser/ast/relationship.rb
puppet-3.8.6-x86-mingw32 lib/puppet/parser/ast/relationship.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/relationship.rb
puppet-3.8.6-x64-mingw32 lib/puppet/parser/ast/relationship.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/relationship.rb
puppet-3.8.5 lib/puppet/parser/ast/relationship.rb
puppet-3.8.5-x86-mingw32 lib/puppet/parser/ast/relationship.rb
puppet-3.8.5-x64-mingw32 lib/puppet/parser/ast/relationship.rb
puppet-3.8.4 lib/puppet/parser/ast/relationship.rb
puppet-3.8.4-x86-mingw32 lib/puppet/parser/ast/relationship.rb
puppet-3.8.4-x64-mingw32 lib/puppet/parser/ast/relationship.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/relationship.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/relationship.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/relationship.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/relationship.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/relationship.rb