<commit_before>require "augeas"
require "forwardable"

module ConfigFiles
  # @note highly coupled with AugeasTree class
  class AugeasCollection
    extend Forwardable
    def initialize(data, name)
      @data = data
      @name = name
      load_collection
    end

    def_delegators :@collection, :[], :empty?, :each, :map, :any?, :all?, :none?

    def add(value, where = { :append => true})
      # TODO
    end

    def delete(matcher)
      key = @name + "[]"
      @data.reject! do |entry|
        entry[:key] == key && matcher === entry[:value]
      end

      load_collection
    end

  private
     def load_collection
      entries = @data.select{|d| d[:key] == @name + "[]"}
      @collection = entries.map{|e| e[:value]}.freeze
     end
  end

  # Represent parsed augeas config tree with user friendly methods
  class AugeasTree
    def initialize
      @data = []
    end

    def collection(key)
      AugeasCollection.new(@data, key)
    end

    def delete(key)<commit_msg>allow low level access to augeas structure<commit_after>require "augeas"
require "forwardable"

module ConfigFiles
  # @note highly coupled with AugeasTree class
  class AugeasCollection
    extend Forwardable
    def initialize(tree, name)
      @tree = tree
      @name = name
      load_collection
    end

    def_delegators :@collection, :[], :empty?, :each, :map, :any?, :all?, :none?

    def add(value, where = { :append => true})
      # TODO
    end

    def delete(matcher)
      key = @name + "[]"
      @tree.data.reject! do |entry|
        entry[:key] == key && matcher === entry[:value]
      end

      load_collection
    end

  private
     def load_collection
      entries = @tree.data.select{|d| d[:key] == @name + "[]"}
      @collection = entries.map{|e| e[:value]}.freeze
     end
  end

  # Represent parsed augeas config tree with user friendly methods
  class AugeasTree
    # low level access to augeas structure
    attr_reader :data

    def initialize
      @data = []
    end

    def collection(key)
      AugeasCollection.new(self, key)
    end

    def delete(key)
{'fraction_non_alphanumeric': 0.11413562559694365, 'fraction_numerical': 0.0, 'mean_word_length': 2.6058519793459554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4250233', 'n_tokens_mistral': 664, 'n_tokens_neox': 643, 'n_words': 189}