Sha256: ae17a9adbefdb7635a47f7449c3cafee71fc11d3c1274cd90bb8ecdbdd583b5c

Contents?: true

Size: 962 Bytes

Versions: 6

Compression:

Stored size: 962 Bytes

Contents

module DbCharmer
  module Sharding
    class Connection
      attr_accessor :config, :sharder

      def initialize(config)
        @config = config
        @sharder = self.instantiate_sharder
      end

      def instantiate_sharder
        raise ArgumentError, "No :method passed!" unless config[:method]
        sharder_class_name = "DbCharmer::Sharding::Method::#{config[:method].to_s.classify}"
        sharder_class = sharder_class_name.constantize
        sharder_class.new(config)
      end

      def reload_sharder
        @sharder = instantiate_sharder
      end

      def shard_connections
        sharder.respond_to?(:shard_connections) ? sharder.shard_connections : nil
      end

      def support_default_shard?
        sharder.respond_to?(:support_default_shard?) && sharder.support_default_shard?
      end

      def default_connection
        @default_connection ||= DbCharmer::Sharding::StubConnection.new(self)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
yam-db-charmer-1.7.4.14 lib/db_charmer/sharding/connection.rb
yam-db-charmer-1.7.4.13 lib/db_charmer/sharding/connection.rb
yam-db-charmer-1.7.4.10 lib/db_charmer/sharding/connection.rb
yam-db-charmer-1.7.4.9 lib/db_charmer/sharding/connection.rb
yam-db-charmer-1.7.4.8 lib/db_charmer/sharding/connection.rb
yam-db-charmer-1.7.4.0 lib/db_charmer/sharding/connection.rb