Sha256: c92c2c43a72516111f3f69d3387917baa75b931f6d8f0d88109fd5bf3b1e24b3
Contents?: true
Size: 1.25 KB
Versions: 2
Compression:
Stored size: 1.25 KB
Contents
require 'active_support/per_thread_registry' module Rails::Sharding class ShardThreadRegistry # creates two thread-specific variables extend ActiveSupport::PerThreadRegistry attr_accessor :_current_shard_group attr_accessor :_current_shard_name def self.connecting_to_master? current_shard_group.nil? || current_shard_name.nil? end def self.connecting_to_shard? !connecting_to_master? end def self.connect_back_to_master! self.current_shard_group = nil self.current_shard_name = nil end # Returns the current shard group (for the current Thread) def self.current_shard_group _current_shard_group end # Sets the current shard group (for the current Thread) def self.current_shard_group=(group) self._current_shard_group = group.blank? ? nil : group.to_sym end # Returns the current shard name (for the current Thread) def self.current_shard_name _current_shard_name end # Sets the current shard name (for the current Thread) def self.current_shard_name=(name) self._current_shard_name = name.blank? ? nil : name.to_sym end def self.current_shard_group_and_name [current_shard_group, current_shard_name] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rails-sharding-0.1.1 | lib/rails/sharding/shard_thread_registry.rb |
rails-sharding-0.1.0 | lib/rails/sharding/shard_thread_registry.rb |