Sha256: 2521508191cbab4fc9a290f98f0bf59f703d73bd45aef7e3a5defae6d3d994f0

Contents?: true

Size: 675 Bytes

Versions: 2

Compression:

Stored size: 675 Bytes

Contents

module ActiveRecordShards
  class ShardSelection
    def initialize
      @on_slave = false
    end

    def shard
      @shard
    end

    def shard=(new_shard)
      @shard = new_shard
    end

    def on_slave?
      @on_slave
    end

    def on_slave=(new_slave)
      @on_slave = (new_slave == true)
    end

    def connection_configuration_name
      shard_name#(RAILS_ENV)
    end

    def shard_name(klass = nil)
      s = "#{RAILS_ENV}"
      if @shard && (klass.nil? || klass.is_sharded?)
        s << '_shard_'
        s << @shard.to_s
      end
      s << "_slave" if @on_slave
      s
    end

    def any?
      @on_slave || @shard.present?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_record_shards-2.0.0.beta2 lib/active_record_shards/shard_selection.rb
active_record_shards-2.0.0.beta1 lib/active_record_shards/shard_selection.rb