<commit_before>class Hiera
  module Backend
    class Multiyaml_backend
      # XXX: There is no option to override the datadir/datafile function logic
      # in Hiera::Backend, so there is a lot of copy paste code from
      # Hiera::Backend and Hiera::Backend::Yaml_backend instead of inheritance
      # or just calling it from here. The Hiera architecture sucks big dongs. :-(

      def initialize(cache=nil)
        require 'yaml'
        Hiera.debug("Hiera MultiYAML-derp backend starting")

        @cache = cache || Filecache.new
      end

      def lookup(key, scope, order_override, resolution_type)
        Hiera.debug("MultiYAML: Entering lookup method in MultiYAML backend!")
        answer = nil

        Config[:multiyaml][:backends].each do |backend|
          backend = backend.to_sym

          Hiera.debug("MultiYAML: Starting with backend #{backend}")
          #Backend.datasourcefiles(:yaml, scope, "yaml", order_override) do |source, yamlfile|
          Backend.datasources(scope, order_override) do |source|
            Hiera.debug("MultiYAML: Looking for data source #{source} in MultiYAML #{backend}")
            yamlfile = Backend.parse_answer(File.join(Config[backend][:datadir], "#{source}.yaml"), scope)
            Hiera.debug("MultiYAML: Overriding yamlfile variable with #{yamlfile}")

            if not File.exist?(yamlfile)
              Hiera.debug("MultiYAML: Cannot find datafile #{yamlfile}, skipping")
              next
            end

            Hiera.debug("MultiYAML: Found datafile #{yamlfile}, hooray!")
            data = @cache.read_file(yamlfile, Hash) do |data|
              YAML.load(data) || {}
            end

            next if data.empty?
            next unless data.include?(key)

            Hiera.debug("MultiYAML: Found #{key} in #{backend}/#{source} with resolution_type #{resolution_type}")

            new_answer = Backend.parse_answer(data[key], scope)
            answer = merge_answer(resolution_type, new_answer, answer)
            if resolution_type == :priority
              break
            end
          end
          Hiera.debug("MultiYAML: Done with backend #{backend}")
        end
<commit_msg>break if resolution is nil<commit_after>class Hiera
  module Backend
    class Multiyaml_backend
      # XXX: There is no option to override the datadir/datafile function logic
      # in Hiera::Backend, so there is a lot of copy paste code from
      # Hiera::Backend and Hiera::Backend::Yaml_backend instead of inheritance
      # or just calling it from here. The Hiera architecture sucks big dongs. :-(

      def initialize(cache=nil)
        require 'yaml'
        Hiera.debug("Hiera MultiYAML-derp backend starting")

        @cache = cache || Filecache.new
      end

      def lookup(key, scope, order_override, resolution_type)
        Hiera.debug("MultiYAML: Entering lookup method in MultiYAML backend!")
        answer = nil

        Config[:multiyaml][:backends].each do |backend|
          backend = backend.to_sym

          Hiera.debug("MultiYAML: Starting with backend #{backend}")
          #Backend.datasourcefiles(:yaml, scope, "yaml", order_override) do |source, yamlfile|
          Backend.datasources(scope, order_override) do |source|
            Hiera.debug("MultiYAML: Looking for key #{key} data source #{source} in MultiYAML #{backend}")
            yamlfile = Backend.parse_answer(File.join(Config[backend][:datadir], "#{source}.yaml"), scope)
            Hiera.debug("MultiYAML: Overriding yamlfile variable with #{yamlfile}")

            if not File.exist?(yamlfile)
              Hiera.debug("MultiYAML: Cannot find datafile #{yamlfile}, skipping")
              next
            end

            Hiera.debug("MultiYAML: Found datafile #{yamlfile}, hooray!")
            data = @cache.read_file(yamlfile, Hash) do |data|
              YAML.load(data) || {}
            end

            next if data.empty?
            next unless data.include?(key)

            Hiera.debug("MultiYAML: Found #{key} in #{backend}/#{source} with resolution_type #{resolution_type}")

            new_answer = Backend.parse_answer(data[key], scope)
            answer = merge_answer(resolution_type, new_answer, answer)
            if resolution_type == :priority || resolution_type.nil?
              break
            end
          end
          Hiera.debug("MultiYAML: Done with backend #{backend}")
        end

{'fraction_non_alphanumeric': 0.10176790571169538, 'fraction_numerical': 0.0, 'mean_word_length': 2.5079491255961845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1198491', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1205, 'n_words': 347}