class Simple::Sharding::ScopeProxy
Return value of the sharding
scope method. Allows us to chain the shard choice with other ActiveRecord scopes
Attributes
original_scope[RW]
Public Class Methods
new(shard_id, original_scope)
click to toggle source
# File lib/simple/sharding/active_record_extensions.rb, line 35 def initialize(shard_id, original_scope) @shard_id = shard_id @original_scope = original_scope end
Public Instance Methods
==(other)
click to toggle source
Delegates == to method_missing
so that User.sharding(:id).where(:name => “Mike”) gets run in the correct shard context when #== is evaluated.
# File lib/simple/sharding/active_record_extensions.rb, line 63 def ==(other) method_missing(:==, other) end
Also aliased as: eql?
method_missing(method, *args, &block)
click to toggle source
# File lib/simple/sharding/active_record_extensions.rb, line 45 def method_missing(method, *args, &block) res = Core.sharding(@shard_id) 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 res.respond_to?(:to_sql) @original_scope = res return self end # return res res end
sharding(shard_id)
click to toggle source
# File lib/simple/sharding/active_record_extensions.rb, line 40 def sharding(shard_id) @shard_id = shard_id self end