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 Method Summary collapse

Instance Method Details

#binding_key(binding) ⇒ Object



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

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

#data_key(name) ⇒ Object



17
18
19
# File 'lib/puppet/pops/binder/key_factory.rb', line 17

def data_key(name)
  [Puppet::Pops::Types::PDataType::DEFAULT, name]
end

#get_type(key) ⇒ Object

Returns the type of the key



57
58
59
60
# File 'lib/puppet/pops/binder/key_factory.rb', line 57

def get_type(key)
  return nil unless key.is_a?(Array)
  key[0]
end

#is_contributions_key?(s) ⇒ Boolean



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

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

#is_data?(key) ⇒ Boolean



44
45
46
47
# File 'lib/puppet/pops/binder/key_factory.rb', line 44

def is_data?(key)
  return false unless key.is_a?(Array) && key[0].is_a?(Puppet::Pops::Types::PAnyType)
  Puppet::Pops::Types::PDataType::DEFAULT.assignable?(key[0])
end

#is_named?(key) ⇒ Boolean



39
40
41
# File 'lib/puppet/pops/binder/key_factory.rb', line 39

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

#is_ruby?(key) ⇒ Boolean



50
51
52
# File 'lib/puppet/pops/binder/key_factory.rb', line 50

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



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

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



28
29
30
# File 'lib/puppet/pops/binder/key_factory.rb', line 28

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

#named_key(type, name) ⇒ Object



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

def named_key(type, name)
  [(Puppet::Pops::Types::PDataType::DEFAULT.assignable?(type) ? Puppet::Pops::Types::PDataType::DEFAULT : type), name]
end