<commit_before>require 'active_record' # change rwebspec/database

module RWebSpec
  module DatabaseChecker

    def mysql_db(settings)
      options = {:adapter => "mysql"}
      options.merge!(settings)
    end

    def sqlite3_db(settings)
      options = {:adapter => "sqlite3"}
      options.merge!(settings)
    end

    # Connect to databse, example
    #   mysql_db(:host => "localhost", :database => "lavabuild_local", :user => "root", :password => "")
    def connect_to_database(db_settings, force = false) 
        # only setup database connection once
        if force || ActiveRecord::Base.connection.nil?
          ActiveRecord::Base.establish_connection(db_settings)
        end        
    end
    
    def load_table(table_name)
      raise "No database connection setup yet, use connect_to_database() method" unless ActiveRecord::Base.connection
      class_name = table_name.classify
      # define the class, so can use ActiveRecord in 
      # such as 
      #   Perosn.count.should == 2
      def_class = "class #{class_name} < ActiveRecord::Base; end"
      eval(def_class);
      return class_name
    end

  end
end<commit_msg>make eval class outside libarry<commit_after>require 'active_record' # change rwebspec/database

module RWebSpec
  module DatabaseChecker

    def mysql_db(settings)
      options = {:adapter => "mysql"}
      options.merge!(settings)
    end

    def sqlite3_db(settings)
      options = {:adapter => "sqlite3"}
      options.merge!(settings)
    end

    # Connect to databse, example
    #   mysql_db(:host => "localhost", :database => "lavabuild_local", :user => "root", :password => "")
    def connect_to_database(db_settings, force = false)
      # only setup database connection once
      if force
        ActiveRecord::Base.establish_connection(db_settings)
      else
        begin
          ActiveRecord::Base.connection
        rescue => e
          ActiveRecord::Base.establish_connection(db_settings)
        end
      end
    end

    def load_table(table_name)
      begin
         ActiveRecord::Base.connection    
      rescue =>e 
        raise "No database connection setup yet, use connect_to_database() method" 
      end
      class_name = table_name.classify
      # define the class, so can use ActiveRecord in
      # such as
      #   Perosn.count.should == 2
      def_class = "class #{class_name} < ActiveRecord::Base; end"        
    end

  end
end
{'fraction_non_alphanumeric': 0.093711467324291, 'fraction_numerical': 0.002466091245376079, 'mean_word_length': 2.7274119448698317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '1985909', 'n_tokens_mistral': 705, 'n_tokens_neox': 682, 'n_words': 181}