<commit_before>require 'ht/template_methods'
module HT
  class Builder
    include TemplateMethods

    attr_reader :data

    def dependency_list(cascade, layer_name)
      if direct_dependency = get_dependency(cascade, layer_name)
        [direct_dependency] + dependency_list(cascade, direct_dependency)
      else 
        []
      end

    end

    def run(cascade, data, name)
      @result = {}
      @data = data

      top = cascade[name]
      dependencies = dependency_list(cascade, name).reverse
      dependencies.each do |dependency|
        next unless cascade.has_key?(dependency) && cascade[dependency].has_key?(:block)
        run_layer cascade[dependency], data
#        instance_exec data, &cascade[dependency][:block]
      end
      
#      instance_exec(data, &top[:block]) if top[:block]
      run_layer top, data

      @data = nil
      @result
    end

    private

    def get_dependency(cascade, layer_name)
      # conditional is to allow hashes in testing
      cascade.respond_to?(:dependency) ? cascade.dependency(layer_name) : cascade[layer_name][:depends]
    end

    def run_layer(layer, data)
      block = layer[:block]
      return unless block

      if block.arity == 2 # support backwards compat. with v0.0.0
        block.call self, data
      else
        instance_exec data, &block
      end
    end
  end
end
<commit_msg>minor lingering commented code removed<commit_after>require 'ht/template_methods'
module HT
  class Builder
    include TemplateMethods

    attr_reader :data

    def dependency_list(cascade, layer_name)
      if direct_dependency = get_dependency(cascade, layer_name)
        [direct_dependency] + dependency_list(cascade, direct_dependency)
      else 
        []
      end

    end

    def run(cascade, data, name)
      @result = {}
      @data = data

      top = cascade[name]
      dependencies = dependency_list(cascade, name).reverse
      dependencies.each do |dependency|
        next unless cascade.has_key?(dependency) && cascade[dependency].has_key?(:block)
        run_layer cascade[dependency], data
      end
      
      run_layer top, data

      @data = nil
      @result
    end

    private

    def get_dependency(cascade, layer_name)
      # conditional is to allow hashes in testing
      cascade.respond_to?(:dependency) ? cascade.dependency(layer_name) : cascade[layer_name][:depends]
    end

    def run_layer(layer, data)
      block = layer[:block]
      return unless block

      if block.arity == 2 # support backwards compat. with v0.0.0
        block.call self, data
      else
        instance_exec data, &block
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08273517189270872, 'fraction_numerical': 0.003022289384208538, 'mean_word_length': 2.6373626373626373, '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': '1827797', 'n_tokens_mistral': 822, 'n_tokens_neox': 746, 'n_words': 201}