<commit_before># encoding: utf-8

# Configuration for a rails app
# @author <NAME>

require 'xapian_db'
require 'rails'

module XapianDb
  class Railtie < ::Rails::Railtie

    config.before_configuration do

      # Read the database configuration file if there is one
      config_file_path = "#{Rails.root}/config/xapian_db.yml"
      if File.exist?(config_file_path)
        db_config = YAML::load_file config_file_path
        env_config = db_config[Rails.env]
        database_path = env_config["database"] || ":memory:"
        adapter       = env_config["adapter"]  || "active_record"
        writer        = env_config["writer"]   || "direct"
      else
        # Set the default database path
        Rails.env == "test" ? database_path = ":memory:" : database_path = "db/xapian_db/#{Rails.env}"
      end
      
      # Do the configuration
      XapianDb::Config.setup do |config|
        if database_path == ":memory:"
          config.database :memory
        else
          config.database database_path
        end
        config.adapter adapter.to_sym  
        config.writer writer
      end
      
    end
    
  end
end<commit_msg>[FIX] fixed default config for Rails (no config file)<commit_after># encoding: utf-8

# Configuration for a rails app
# @author <NAME>

require 'xapian_db'
require 'rails'

module XapianDb
  class Railtie < ::Rails::Railtie

    config.before_configuration do

      # Read the database configuration file if there is one
      config_file_path = "#{Rails.root}/config/xapian_db.yml"
      if File.exist?(config_file_path)
        db_config = YAML::load_file config_file_path
        env_config = db_config[Rails.env]
        database_path = env_config["database"] || ":memory:"
        adapter       = env_config["adapter"]  || :active_record
        writer        = env_config["writer"]   || :direct
      else
        # No config file, set the defaults
        Rails.env == "test" ? database_path = ":memory:" : database_path = "db/xapian_db/#{Rails.env}"
        adapter = :active_record
        writer  = :direct
      end
      
      # Do the configuration
      XapianDb::Config.setup do |config|
        if database_path == ":memory:"
          config.database :memory
        else
          config.database database_path
        end
        config.adapter adapter.to_sym  
        config.writer writer.to_sym
      end
      
    end
    
  end
end
{'fraction_non_alphanumeric': 0.09630552096305521, 'fraction_numerical': 0.0008302200083022001, 'mean_word_length': 2.3753501400560224, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 5, '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': '4004708', 'n_tokens_mistral': 731, 'n_tokens_neox': 711, 'n_words': 180}