Sha256: 8640a26198795bde6857a9eff329452f425995ee0a0c6621b9b2f098d6f78f9c

Contents?: true

Size: 1.53 KB

Versions: 18

Compression:

Stored size: 1.53 KB

Contents

# The KeyFactory is responsible for creating keys used for lookup of bindings.
# @api public
#
class Puppet::Pops::Binder::KeyFactory

  attr_reader :type_calculator
  # @api public
  def initialize(type_calculator = Puppet::Pops::Types::TypeCalculator.new())
    @type_calculator = type_calculator
  end

  # @api public
  def binding_key(binding)
    named_key(binding.type, binding.name)
  end

  # @api public
  def named_key(type, name)
    [(@type_calculator.assignable?(@type_calculator.data, type) ? @type_calculator.data : type), name]
  end

  # @api public
  def data_key(name)
    [@type_calculator.data, name]
  end

  # @api public
  def is_contributions_key?(s)
    return false unless s.is_a?(String)
    s.start_with?('mc_')
  end

  # @api public
  def multibind_contributions(multibind_id)
    "mc_#{multibind_id}"
  end

  # @api public
  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

  # @api public
  def is_named?(key)
    key.is_a?(Array) && key[1] && !key[1].empty?
  end

  # @api public
  def is_data?(key)
    return false unless key.is_a?(Array) && key[0].is_a?(Puppet::Pops::Types::PObjectType)
    type_calculator.assignable?(type_calculator.data(), key[0])
  end

  # @api public
  def is_ruby?(key)
    return key.is_a?(Array) && key[0].is_a?(Puppet::Pops::Types::PRubyType)
  end

  # Returns the type of the key
  # @api public
  #
  def get_type(key)
    return nil unless key.is_a?(Array)
    key[0]
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
puppet-3.6.2 lib/puppet/pops/binder/key_factory.rb
puppet-3.6.2-x86-mingw32 lib/puppet/pops/binder/key_factory.rb
puppet-3.6.1 lib/puppet/pops/binder/key_factory.rb
puppet-3.6.1-x86-mingw32 lib/puppet/pops/binder/key_factory.rb
puppet-3.6.0 lib/puppet/pops/binder/key_factory.rb
puppet-3.6.0-x86-mingw32 lib/puppet/pops/binder/key_factory.rb
puppet-3.6.0.rc1 lib/puppet/pops/binder/key_factory.rb
puppet-3.6.0.rc1-x86-mingw32 lib/puppet/pops/binder/key_factory.rb
puppet-3.5.1 lib/puppet/pops/binder/key_factory.rb
puppet-3.5.1-x86-mingw32 lib/puppet/pops/binder/key_factory.rb
puppet-3.5.1.rc1 lib/puppet/pops/binder/key_factory.rb
puppet-3.5.1.rc1-x86-mingw32 lib/puppet/pops/binder/key_factory.rb
puppet-3.5.0.rc3 lib/puppet/pops/binder/key_factory.rb
puppet-3.5.0.rc3-x86-mingw32 lib/puppet/pops/binder/key_factory.rb
puppet-3.5.0.rc2 lib/puppet/pops/binder/key_factory.rb
puppet-3.5.0.rc2-x86-mingw32 lib/puppet/pops/binder/key_factory.rb
puppet-3.5.0.rc1 lib/puppet/pops/binder/key_factory.rb
puppet-3.5.0.rc1-x86-mingw32 lib/puppet/pops/binder/key_factory.rb