class Rails::Sharding::ActiveRecordExtensions::ScopeProxy
Return value of the using_shard
scope method. Allows us to chain the shard choice with other ActiveRecord scopes
Attributes
original_scope[RW]
Public Class Methods
new(shard_group, shard_name, original_scope)
click to toggle source
# File lib/rails/sharding/active_record_extensions.rb, line 44 def initialize(shard_group, shard_name, original_scope) @shard_group = shard_group @shard_name = shard_name @original_scope = original_scope end
Public Instance Methods
==(other)
click to toggle source
Delegates == to method_missing
so that User.using_scope(:a,:b).where(:name => “Mike”) gets run in the correct shard context when #== is evaluated.
# File lib/rails/sharding/active_record_extensions.rb, line 75 def ==(other) method_missing(:==, other) end
Also aliased as: eql?
method_missing(method, *args, &block)
click to toggle source
# File lib/rails/sharding/active_record_extensions.rb, line 57 def method_missing(method, *args, &block) # runs any method chained in the correct shard result = Core.using_shard(@shard_group, @shard_name) do @original_scope.send(method, *args, &block) end # if result is still a scope (responds to to_sql), update original scope # and return proxy to continue chaining if result.respond_to?(:to_sql) @original_scope = result return self end result end
using_shard(shard_group, shard_name)
click to toggle source
if using_shard
is called twice in a chain, just replaces configuration
# File lib/rails/sharding/active_record_extensions.rb, line 51 def using_shard(shard_group, shard_name) @shard_group = shard_group @shard_name = shard_name self end