Method: Puppet::Pops::Functions::Dispatch#weave

Defined in:
lib/puppet/pops/functions/dispatch.rb

#weave(scope, args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/puppet/pops/functions/dispatch.rb', line 69

def weave(scope, args)
  # no need to weave if there are no injections
  if @injections.empty?
    args
  else
    new_args = []
    @weaving.each do |knit|
      if knit.is_a?(Array)
        injection_name = @injections[knit[0]]
        new_args <<
          case injection_name
          when :scope
            scope
          when :pal_script_compiler
            Puppet.lookup(:pal_script_compiler)
          when :cache
            Puppet::Pops::Adapters::ObjectIdCacheAdapter.adapt(scope.compiler)
          when :pal_catalog_compiler
            Puppet.lookup(:pal_catalog_compiler)
          when :pal_compiler
            Puppet.lookup(:pal_compiler)
          else
            raise ArgumentError, _("Unknown injection %{injection_name}") % { injection_name: injection_name }
          end
      elsif knit < 0
        # Careful so no new nil arguments are added since they would override default
        # parameter values in the received
        idx = -knit - 1
        new_args += args[idx..] if idx < args.size
      elsif knit < args.size
        new_args << args[knit]
      end
    end
    new_args
  end
end