<commit_before>require 'mongo'
require 'facets'
require 'yaml'

module YogiBerra
  class Catcher
    extend Facets
    cattr_accessor :settings, :mongo_client, :connection

    class << self
      def load_db_settings(config_file = nil)
        if config_file
          database_config = config_file
        elsif defined?(Rails)
          database_config = "#{Rails.root}/config/yogi.yml"
        else
          YogiBerra::Logger.log("No config file specified!", :error)
        end
        if database_config
          begin
            File.open(database_config, 'r') do |f|
              yaml_file = YAML.load(f)
              environment = (ENV["YOGI_ENV"] || ENV["RAILS_ENV"] || "test")
              @@settings = yaml_file["#{environment}"] if yaml_file
            end
          rescue
            YogiBerra::Logger.log("No such file: #{database_config}", :error)
          end
          @@settings
        end
      end

      def db_client(host, port, replica_set = nil)
        # :w => 0 set the default write concern to 0, this allows writes to be non-blocking
        # by not waiting for a response from mongodb
        if replica_set
          @@mongo_client = Mongo::MongoClient.new(replica_set, :w => 0)
        else
          @@mongo_client = Mongo::MongoClient.new(host, port, :w => 0)<commit_msg>use Mongo::MongoReplicaSetClient.new for replica sets<commit_after>require 'mongo'
require 'facets'
require 'yaml'

module YogiBerra
  class Catcher
    extend Facets
    cattr_accessor :settings, :mongo_client, :connection

    class << self
      def load_db_settings(config_file = nil)
        if config_file
          database_config = config_file
        elsif defined?(Rails)
          database_config = "#{Rails.root}/config/yogi.yml"
        else
          YogiBerra::Logger.log("No config file specified!", :error)
        end
        if database_config
          begin
            File.open(database_config, 'r') do |f|
              yaml_file = YAML.load(f)
              environment = (ENV["YOGI_ENV"] || ENV["RAILS_ENV"] || "test")
              @@settings = yaml_file["#{environment}"] if yaml_file
            end
          rescue
            YogiBerra::Logger.log("No such file: #{database_config}", :error)
          end
          @@settings
        end
      end

      def db_client(host, port, replica_set = nil)
        # :w => 0 set the default write concern to 0, this allows writes to be non-blocking
        # by not waiting for a response from mongodb
        if replica_set
          @@mongo_client = Mongo::MongoReplicaSetClient.new(replica_set, :w => 0)
        else
          @@mongo_client = Mongo::MongoClient.new(host, port, :w => 0)
{'fraction_non_alphanumeric': 0.10104399701715137, 'fraction_numerical': 0.002982848620432513, 'mean_word_length': 2.2170263788968825, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7117573', 'n_tokens_mistral': 843, 'n_tokens_neox': 797, 'n_words': 211}