<commit_before>require 'active_record'
require 'rexml/document'
require 'net/http'
require 'yaml'
require 'time'
require 'erb'
require 'rexml/xpath'

require File.dirname(__FILE__) + '/solr'
require File.dirname(__FILE__) + '/acts_as_solr/acts_methods'
require File.dirname(__FILE__) + '/acts_as_solr/common_methods'
require File.dirname(__FILE__) + '/acts_as_solr/parser_methods'
require File.dirname(__FILE__) + '/acts_as_solr/class_methods'
require File.dirname(__FILE__) + '/acts_as_solr/dynamic_attribute'
require File.dirname(__FILE__) + '/acts_as_solr/local'
require File.dirname(__FILE__) + '/acts_as_solr/instance_methods'
require File.dirname(__FILE__) + '/acts_as_solr/common_methods'
require File.dirname(__FILE__) + '/acts_as_solr/deprecation'
require File.dirname(__FILE__) + '/acts_as_solr/search_results'
require File.dirname(__FILE__) + '/acts_as_solr/lazy_document'
require File.dirname(__FILE__) + '/acts_as_solr/mongo_mapper'

module ActsAsSolr

  class Post    
    def self.execute(request, core = nil)
      config_file_path = File.join(Rails.root, '/config/solr.yml')
      config = YAML::load_file(config_file_path)[Rails.env]
      url = config['url'] + (core.nil? ? '' : "/#{core}")
      connection = Solr::Connection.new(url,
                                        :username => config['username'],
                                        :password => config['password'])
      connection.send request
    end
  end
end

# reopen ActiveRecord and include the acts_as_solr method<commit_msg>caches the configuration, rather than parsing the YAML file in each call to Post.execute<commit_after>require 'active_record'
require 'rexml/document'
require 'net/http'
require 'yaml'
require 'time'
require 'erb'
require 'rexml/xpath'

require File.dirname(__FILE__) + '/solr'
require File.dirname(__FILE__) + '/acts_as_solr/acts_methods'
require File.dirname(__FILE__) + '/acts_as_solr/common_methods'
require File.dirname(__FILE__) + '/acts_as_solr/parser_methods'
require File.dirname(__FILE__) + '/acts_as_solr/class_methods'
require File.dirname(__FILE__) + '/acts_as_solr/dynamic_attribute'
require File.dirname(__FILE__) + '/acts_as_solr/local'
require File.dirname(__FILE__) + '/acts_as_solr/instance_methods'
require File.dirname(__FILE__) + '/acts_as_solr/common_methods'
require File.dirname(__FILE__) + '/acts_as_solr/deprecation'
require File.dirname(__FILE__) + '/acts_as_solr/search_results'
require File.dirname(__FILE__) + '/acts_as_solr/lazy_document'
require File.dirname(__FILE__) + '/acts_as_solr/mongo_mapper'

module ActsAsSolr
  class Post
    class << self
      def config
        @config ||= YAML::load_file("#{Rails.root}/config/solr.yml")[Rails.env]
      end

      def credentials
        @credentials ||= {:username => config['username'], :password => config['password']}
      end

      def url(core)
        core.nil? ? config['url'] : "#{config['url']}/#{core}"
      end
    
      def execute(request, core = nil)
        connection = Solr::Connection.new(url(core), credentials)
        connection.send request
      end
    end
  end
end

# reopen ActiveRecord and include the acts_as_solr method
{'fraction_non_alphanumeric': 0.12579214195183777, 'fraction_numerical': 0.0, 'mean_word_length': 4.3599320882852295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1832540', 'n_tokens_mistral': 1008, 'n_tokens_neox': 994, 'n_words': 198}