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

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

Instance Method Summary collapse

Instance Method Details

#binding_key(binding) ⇒ Object



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

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

#data_key(name) ⇒ Object



19
20
21
# File 'lib/puppet/pops/binder/key_factory.rb', line 19

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

#get_type(key) ⇒ Object

Returns the type of the key



59
60
61
62
# File 'lib/puppet/pops/binder/key_factory.rb', line 59

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

#is_contributions_key?(s) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#is_data?(key) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/puppet/pops/binder/key_factory.rb', line 46

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

#is_named?(key) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/puppet/pops/binder/key_factory.rb', line 41

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

#is_ruby?(key) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/puppet/pops/binder/key_factory.rb', line 52

def is_ruby?(key)
  key.is_a?(Array) && key[0].is_a?(Types::PRuntimeType) && key[0].runtime == :ruby
end

#multibind_contribution_key_to_id(contributions_key) ⇒ Object



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

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



30
31
32
# File 'lib/puppet/pops/binder/key_factory.rb', line 30

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

#named_key(type, name) ⇒ Object



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

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