Module: Octopus::ShardTracking

Defined in:
lib/octopus/shard_tracking.rb,
lib/octopus/shard_tracking/dynamic.rb,
lib/octopus/shard_tracking/attribute.rb

Defined Under Namespace

Modules: Attribute, ClassMethods, Dynamic

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/octopus/shard_tracking.rb', line 3

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#run_on_shard(&block) ⇒ Object

Adds run_on_shard method, but does not implement current_shard method



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/octopus/shard_tracking.rb', line 29

def run_on_shard(&block)
  if (cs = current_shard)
    r = ActiveRecord::Base.connection_proxy.run_queries_on_shard(cs, &block)
    # Use a case statement to avoid any path through ActiveRecord::Delegation's
    # respond_to? code. We want to avoid the respond_to? code because it can have
    # the side effect of causing a call to load_target

    if (ActiveRecord::Relation === r || ActiveRecord::QueryMethods::WhereChain === r) && !(Octopus::RelationProxy === r)
      Octopus::RelationProxy.new(cs, r)
    else
      r
    end
  else
    yield
  end
end