Sha256: d46c8cfb1be8be47641ab34eac6b928d36ae978e9e684d4f61cfb13921c8d569

Contents?: true

Size: 1.01 KB

Versions: 63

Compression:

Stored size: 1.01 KB

Contents

module Puppet::DataProviders::DataFunctionSupport
  def initialize_data(data_key, lookup_invocation)
    name = "#{data_key}::data"
    scope = lookup_invocation.scope
    Puppet::Util::Profiler.profile("Called #{name}", [ :functions, name ]) do
      loader = loader(data_key, scope)
      if loader && func = loader.load(:function, name)
        # function found, call without arguments, must return a Hash
        # TODO: Validate the function - to ensure it does not contain unwanted side effects
        #       That can only be done if the function is a puppet function
        #
        result = func.call(scope)
        unless result.is_a?(Hash)
          raise Puppet::Error.new("Expected '#{name}' function to return a Hash, got #{result.class}")
        end
        # validate result if block given
        result = yield(result) if block_given?
      else
        raise Puppet::Error.new("Cannot find the function '#{name}' - required when using 'function' data provider scheme")
      end
      result
    end
  end
end

Version data entries

63 entries across 63 versions & 2 rubygems

Version Path
puppet-retrospec-1.5.0 vendor/gems/puppet-4.5.2/lib/puppet/data_providers/data_function_support.rb
puppet-retrospec-1.4.1 vendor/gems/puppet-4.5.2/lib/puppet/data_providers/data_function_support.rb
puppet-retrospec-1.4.0 vendor/gems/puppet-4.5.2/lib/puppet/data_providers/data_function_support.rb
puppet-retrospec-1.3.2 vendor/gems/puppet-4.5.2/lib/puppet/data_providers/data_function_support.rb
puppet-retrospec-1.3.1 vendor/gems/puppet-4.5.2/lib/puppet/data_providers/data_function_support.rb
puppet-retrospec-1.3.0 vendor/gems/puppet-4.5.2/lib/puppet/data_providers/data_function_support.rb
puppet-4.7.1 lib/puppet/data_providers/data_function_support.rb
puppet-4.7.1-x86-mingw32 lib/puppet/data_providers/data_function_support.rb
puppet-4.7.1-x64-mingw32 lib/puppet/data_providers/data_function_support.rb
puppet-4.7.1-universal-darwin lib/puppet/data_providers/data_function_support.rb
puppet-retrospec-1.2.1 vendor/gems/puppet-4.5.2/lib/puppet/data_providers/data_function_support.rb
puppet-retrospec-1.2.0 vendor/gems/puppet-4.5.2/lib/puppet/data_providers/data_function_support.rb
puppet-4.7.0 lib/puppet/data_providers/data_function_support.rb
puppet-4.7.0-x86-mingw32 lib/puppet/data_providers/data_function_support.rb
puppet-4.7.0-x64-mingw32 lib/puppet/data_providers/data_function_support.rb
puppet-4.7.0-universal-darwin lib/puppet/data_providers/data_function_support.rb
puppet-4.6.2 lib/puppet/data_providers/data_function_support.rb
puppet-4.6.2-x86-mingw32 lib/puppet/data_providers/data_function_support.rb
puppet-4.6.2-x64-mingw32 lib/puppet/data_providers/data_function_support.rb
puppet-4.6.2-universal-darwin lib/puppet/data_providers/data_function_support.rb