<commit_before>class ActionPresenter::Base
  def initialize(template, *args)
    @_template = template
    @options = args.extract_options!
    @object = args.first
  end

  attr_reader :object, :options
  delegate :present, :present_collection, to: :h
  protected :present, :present_collection, :options
 
  def self.presents(name)
    define_method name do
      self.object
    end
  end
  
  def self.delegate_presented(name, options = {})
    delegate_opts = options.slice(:to, :prefix, :allow_nil).reverse_merge(to: :object)
    delegate name, delegate_opts
    
    define_method "#{name}_with_presenter" do
      delegated_obj = self.public_send("#{name}_without_presenter")
      present delegated_obj, options.except(*delegate_opts.keys) unless delegated_obj.nil?
    end
    
    alias_method_chain name, :presenter
  end

  def inspect
    if object.nil?
      "#<#{self.class.name}>"
    else
      "#<#{self.class.name} object: #{object.inspect}>"
    end
  end

  def method_missing(name, *args, &block)
    if object and object.respond_to?(name, false)
      object.send(name, *args, &block)
    else
      super
    end
  end

  def respond_to_missing?(name, include_private = false)
    (object && object.respond_to?(name, include_private)) || super
  end

  def to_model
    object
  end

  protected
  def template
    @_template
  end
  alias_method :h, :template
end
<commit_msg>Enhances ActionPresenter::Base to take care of present_collection helper<commit_after>class ActionPresenter::Base
  def initialize(template, *args)
    @_template = template
    @options = args.extract_options!
    @object = args.first
  end

  attr_reader :object, :options
  delegate :present, :present_collection, to: :h
  protected :present, :present_collection, :options
 
  def self.presents(name)
    define_method name do
      object
    end
  end
  
  def self.delegate_presented(name, options = {})
    delegate_opts = options.slice(:to, :prefix, :allow_nil)
                    .reverse_merge(to: :object)
    delegate name, delegate_opts
    
    define_method "#{name}_with_presenter" do
      object = public_send("#{name}_without_presenter")
      return if object.nil?
      helper_options = options.except(*delegate_opts.keys)
      if object.respond_to?(:each) && options.fetch(:resolve_collection, false)
        present_collection object, helper_options
      else
        present object, helper_options
      end
    end
    
    alias_method_chain name, :presenter
  end

  def inspect
    if object.nil?
      "#<#{self.class.name}>"
    else
      "#<#{self.class.name} object: #{object.inspect}>"
    end
  end

  def method_missing(name, *args, &block)
    if object && object.respond_to?(name, false)
      object.send(name, *args, &block)
    else
      super
    end
  end

  def respond_to_missing?(name, include_private = false)
    (object && object.respond_to?(name, include_private)) || super
  end

  def to_model
    object
  end

  protected
  def template
    @_template
  end
  alias_method :h, :template
end

{'fraction_non_alphanumeric': 0.10163934426229508, 'fraction_numerical': 0.0, 'mean_word_length': 3.243393602225313, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7631738', 'n_tokens_mistral': 962, 'n_tokens_neox': 961, 'n_words': 233}