Class: Puppet::Pops::Binder::KeyFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/binder/key_factory.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_calculator = Puppet::Pops::Types::TypeCalculator.new()) ⇒ KeyFactory

Returns a new instance of KeyFactory.



8
9
10
# File 'lib/puppet/pops/binder/key_factory.rb', line 8

def initialize(type_calculator = Puppet::Pops::Types::TypeCalculator.new())
  @type_calculator = type_calculator
end

Instance Attribute Details

#type_calculatorObject (readonly)



6
7
8
# File 'lib/puppet/pops/binder/key_factory.rb', line 6

def type_calculator
  @type_calculator
end

Instance Method Details

#binding_key(binding) ⇒ Object



13
14
15
# File 'lib/puppet/pops/binder/key_factory.rb', line 13

def binding_key(binding)
  named_key(binding.type, binding.name)
end

#data_key(name) ⇒ Object



23
24
25
# File 'lib/puppet/pops/binder/key_factory.rb', line 23

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

#get_type(key) ⇒ Object

Returns the type of the key



63
64
65
66
# 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) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
# 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) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
# 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) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# 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) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# 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) ⇒ Object



39
40
41
42
# 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) ⇒ Object



34
35
36
# File 'lib/puppet/pops/binder/key_factory.rb', line 34

def multibind_contributions(multibind_id)
  "mc_#{multibind_id}"
end

#named_key(type, name) ⇒ Object



18
19
20
# 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