<commit_before>module Draper
  class DecoratedEnumerableProxy
    include Enumerable

    def initialize(collection, klass, options = {})
      @wrapped_collection, @klass, @options = collection, klass, options
    end

    def each(&block)
      @wrapped_collection.each { |member| block.call(@klass.decorate(member, @options)) }
    end

    def to_ary
      @wrapped_collection.map { |member| @klass.decorate(member, @options) }
    end

    def method_missing (method, *args, &block)
      # this is absolutely gross, but for now, it works.
      # There should be a better solution, for sure.
      if method == :last && @wrapped_collection.respond_to?(:last)
        @klass.decorate(@wrapped_collection.last)
      elsif method == :shift && @wrapped_collection.respond_to?(:shift)
        @klass.decorate(@wrapped_collection.shift)
      else
        @wrapped_collection.send(method, *args, &block)
      end
    end

    def respond_to?(method, include_private = false)
      super || @wrapped_collection.respond_to?(method, include_private)
    end

    def kind_of?(klass)
      @wrapped_collection.kind_of?(klass) || super
    end
    alias :is_a? :kind_of?

    def ==(other)
      @wrapped_collection == other
    end

    def [](index)
      @klass.new(@wrapped_collection[index], @options)
    end

    def to_s
      "#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>"
    end
    
    def context=(input)
      self.map { |member| member.context = input }
    end

    def source
      @wrapped_collection
    end
    alias_method :to_source, :source
  end
end
<commit_msg>Delegating a bunch of methods to #decorated_collection.<commit_after>module Draper
  class DecoratedEnumerableProxy
    include Enumerable

    delegate :as_json, :collect, :map, :each, :[], :all?, :include?, :first, :last, :shift, :to => :decorated_collection

    def initialize(collection, klass, options = {})
      @wrapped_collection, @klass, @options = collection, klass, options
    end

    def decorated_collection
      @decorated_collection ||= @wrapped_collection.collect { |member| @klass.decorate(member, @options) }
    end
    alias_method :to_ary, :decorated_collection

    def method_missing (method, *args, &block)
      @wrapped_collection.send(method, *args, &block)
    end

    def respond_to?(method, include_private = false)
      super || @wrapped_collection.respond_to?(method, include_private)
    end

    def kind_of?(klass)
      @wrapped_collection.kind_of?(klass) || super
    end
    alias :is_a? :kind_of?

    def ==(other)
      @wrapped_collection == other
    end

    def [](index)
      @klass.new(@wrapped_collection[index], @options)
    end

    def to_s
      "#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>"
    end
    
    def context=(input)
      self.map { |member| member.context = input }
    end

    def source
      @wrapped_collection
    end
    alias_method :to_source, :source
  end
end

{'fraction_non_alphanumeric': 0.1115937186769128, 'fraction_numerical': 0.0, 'mean_word_length': 3.2288135593220337, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '1355132', 'n_tokens_mistral': 940, 'n_tokens_neox': 947, 'n_words': 224}