Sha256: f6040e1cfb4e797e19164c53a3536928beea9be9140f04f6230092e8a8b16a84

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

module Tako
  class Repository
    class << self
      def proxy_configs
        @proxy_configs ||= {}
      end

      def proxy_connections
        @proxy_connections ||= {}
      end

      def clear
        proxy_connections.each do |shard_name, connection|
          connection.disconnect!
          remove_const("TAKO_AR_CLASS_#{shard_name.upcase}")
        end
        proxy_configs.clear
        proxy_connections.clear
      end

      def add(shard_name, conf)
        shard_name = shard_name.to_sym
        return if proxy_configs[shard_name]

        temporary_class = Class.new(ActiveRecord::Base)
        const_set("TAKO_AR_CLASS_#{shard_name.upcase}", temporary_class)
        temporary_class.establish_connection(conf)

        proxy_connections[shard_name] = temporary_class.connection
        proxy_configs[shard_name] = conf
      end

      def create_proxy(shard_name)
        Proxy.new(shard_name, proxy_connections[shard_name.to_sym])
      end

      def shard_names
        proxy_configs.keys
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tako-0.5.0 lib/tako/repository.rb
tako-0.4.1 lib/tako/repository.rb
tako-0.4.0 lib/tako/repository.rb
tako-0.3.2 lib/tako/repository.rb
tako-0.3.1 lib/tako/repository.rb