class Puppet::Pops::Binder::KeyFactory

The KeyFactory is responsible for creating keys used for lookup of bindings. @api public

Attributes

type_calculator[R]

Public Instance Methods

binding_key(binding) click to toggle source

@api public

# File lib/puppet/pops/binder/key_factory.rb, line 13
def binding_key(binding)
  named_key(binding.type, binding.name)
end
data_key(name) click to toggle source

@api public

# File lib/puppet/pops/binder/key_factory.rb, line 23
def data_key(name)
  [@type_calculator.data, name]
end
get_type(key) click to toggle source

Returns the type of the key @api public

# File lib/puppet/pops/binder/key_factory.rb, line 63
def get_type(key)
  return nil unless key.is_a?(Array)
  key[0]
end
is_contributions_key?(s) click to toggle source

@api public

# File lib/puppet/pops/binder/key_factory.rb, line 28
def is_contributions_key?(s)
  return false unless s.is_a?(String)
  s.start_with?('mc_')
end
is_data?(key) click to toggle source

@api public

# File lib/puppet/pops/binder/key_factory.rb, line 50
def is_data?(key)
  return false unless key.is_a?(Array) && key[0].is_a?(Puppet::Pops::Types::PAnyType)
  type_calculator.assignable?(type_calculator.data(), key[0])
end
is_named?(key) click to toggle source

@api public

# File lib/puppet/pops/binder/key_factory.rb, line 45
def is_named?(key)
  key.is_a?(Array) && key[1] && !key[1].empty?
end
is_ruby?(key) click to toggle source

@api public

# File lib/puppet/pops/binder/key_factory.rb, line 56
def is_ruby?(key)
  key.is_a?(Array) && key[0].is_a?(Puppet::Pops::Types::PRuntimeType) && key[0].runtime == :ruby
end
multibind_contribution_key_to_id(contributions_key) click to toggle source

@api public

# File lib/puppet/pops/binder/key_factory.rb, line 39
def multibind_contribution_key_to_id(contributions_key)
  # removes the leading "mc_" from the key to get the multibind_id
  contributions_key[3..-1]
end
multibind_contributions(multibind_id) click to toggle source

@api public

# File lib/puppet/pops/binder/key_factory.rb, line 34
def multibind_contributions(multibind_id)
  "mc_#{multibind_id}"
end
named_key(type, name) click to toggle source

@api public

# File lib/puppet/pops/binder/key_factory.rb, line 18
def named_key(type, name)
  [(@type_calculator.assignable?(@type_calculator.data, type) ? @type_calculator.data : type), name]
end

Public Class Methods

new(type_calculator = Puppet::Pops::Types::TypeCalculator.new()) click to toggle source

@api public

# File lib/puppet/pops/binder/key_factory.rb, line 8
def initialize(type_calculator = Puppet::Pops::Types::TypeCalculator.new())
  @type_calculator = type_calculator
end