Module: Octopus::ShardTracking::Attribute

Included in:
RelationProxy, Octopus::ScopeProxy
Defined in:
lib/octopus/shard_tracking/attribute.rb

Overview

Adds current_shard as an attribute; provide a default implementation of set_current_shard which considers only the current ActiveRecord::Base.connection_proxy

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
# File 'lib/octopus/shard_tracking/attribute.rb', line 5

def self.included(base)
  base.send(:include, Octopus::ShardTracking)
  base.extend(ClassMethods)
  base.track_current_shard_as_attribute
end

Instance Method Details

#set_current_shardObject



17
18
19
20
21
22
23
# File 'lib/octopus/shard_tracking/attribute.rb', line 17

def set_current_shard
  return unless Octopus.enabled?

  if ActiveRecord::Base.connection_proxy.block
    self.current_shard = ActiveRecord::Base.connection_proxy.current_shard
  end
end