<commit_before>require 'active_record'
prefix = defined?(JRUBY_VERSION) ? "jdbc" : ""
require "active_record/connection_adapters/#{prefix}mysql_adapter"
begin
  require "active_record/connection_adapters/#{prefix}postgresql_adapter"
rescue LoadError
  # No postgres?  no prob...
end
require 'yaml'

class SphinxHelper
  attr_accessor :host, :username, :password
  attr_reader   :path
  
  def initialize
    @host     = "localhost"
    @username = "thinking_sphinx"
    @password = ""

    if File.exist?("spec/fixtures/database.yml")
      config    = YAML.load(File.open("spec/fixtures/database.yml"))
      @host     = config["host"]
      @username = config["username"]
      @password = config["password"]
    end
    
    @path = File.expand_path(File.dirname(__FILE__))
  end
  
  def mysql_adapter
    defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'
  end
  
  def setup_mysql
    ActiveRecord::Base.establish_connection(
      :adapter  => mysql_adapter,
      :database => 'thinking_sphinx',
      :username => @username,
      :password => <PASSWORD>,
      :host     => @host
    )
    ActiveRecord::Base.logger = Logger.new(File.open("tmp/activerecord.log", "a"))
    
    structure = File.open("spec/fixtures/structure.sql") { |f| f.read.chomp }
    structure.split(';').each { |table|
      ActiveRecord::Base.connection.execute table<commit_msg>updated sphinx helper to allow for custom socket declarations in the database.yml<commit_after>require 'active_record'
prefix = defined?(JRUBY_VERSION) ? "jdbc" : ""
require "active_record/connection_adapters/#{prefix}mysql_adapter"
begin
  require "active_record/connection_adapters/#{prefix}postgresql_adapter"
rescue LoadError
  # No postgres?  no prob...
end
require 'yaml'

class SphinxHelper
  attr_accessor :host, :username, :password, :socket
  attr_reader   :path
  
  def initialize
    @host     = "localhost"
    @username = "thinking_sphinx"
    @password = ""

    if File.exist?("spec/fixtures/database.yml")
      config    = YAML.load(File.open("spec/fixtures/database.yml"))
      @host     = config["host"]
      @username = config["username"]
      @password = config["password"]
      @socket   = config["socket"]
    end
    
    @path = File.expand_path(File.dirname(__FILE__))
  end
  
  def mysql_adapter
    defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'
  end
  
  def setup_mysql
    ActiveRecord::Base.establish_connection(
      :adapter  => mysql_adapter,
      :database => 'thinking_sphinx',
      :username => @username,
      :password => <PASSWORD>,
      :host     => @host,
      :socket   => @socket
    )
    ActiveRecord::Base.logger = Logger.new(File.open("tmp/activerecord.log", "a"))
    
    structure = File.open("spec/fixtures/structure.sql") { |f| f.read.chomp }
    structure.split(';').each { |table|
      ActiveRecord::Base.connection.execute table
{'fraction_non_alphanumeric': 0.13487071977638015, 'fraction_numerical': 0.0, 'mean_word_length': 3.4456521739130435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '1319131', 'n_tokens_mistral': 940, 'n_tokens_neox': 912, 'n_words': 171}