<commit_before>require 'sinatra/base'
require 'mongo'

module Sinatra
  module MongoHelper
    def mongo
      options.mongo
    end
  end

  module MongoExtension
    def mongo=(url)
      @mongo = nil
      set :mongo_url, url
      mongo
    end

    def mongo
      @mongo ||= (
        url = URI(mongo_url)
        connection = Mongo::Connection.new(url.host, url.port)
        mongo = connection.db(url.path[1..-1])
        if url.user && url.password
          mongo.authenticate(url.user, url.password)
        end
        mongo
      )
    end

    protected

    def self.registered(app)
      app.set :mongo_url, ENV['MONGO_URL'] || 'mongo://127.0.0.1:27017/default'
      app.helpers MongoHelper
    end

  end

  register MongoExtension

end<commit_msg>be mindful of threaded apps<commit_after>require 'sinatra/base'
require 'mongo'

module Sinatra
  module MongoHelper
    def mongo
      options.mongo
    end
  end

  module MongoExtension
    def mongo=(url)
      @mongo = nil
      set :mongo_url, url
      mongo
    end

    def mongo
      synchronize do
        @mongo ||= (
          url = URI(mongo_url)
          connection = Mongo::Connection.new(url.host, url.port)
          mongo = connection.db(url.path[1..-1])
          if url.user && url.password
            mongo.authenticate(url.user, url.password)
          end
          mongo
        )
      end
    end

    protected

    def self.registered(app)
      app.set :mongo_url, ENV['MONGO_URL'] || 'mongo://127.0.0.1:27017/default'
      app.helpers MongoHelper
    end

  end

  register MongoExtension

end
{'fraction_non_alphanumeric': 0.09655172413793103, 'fraction_numerical': 0.016300940438871474, 'mean_word_length': 1.9887640449438202, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '7109057', 'n_tokens_mistral': 561, 'n_tokens_neox': 523, 'n_words': 118}