class Octopus::ScopeProxy
Attributes
klass[RW]
Public Class Methods
new(shard, klass)
click to toggle source
# File lib/octopus/scope_proxy.rb, line 18 def initialize(shard, klass) @current_shard = shard @klass = klass end
Public Instance Methods
==(other)
click to toggle source
Delegates to method_missing
(instead of @klass) so that User.using(:blah).where(:name => “Mike”) gets run in the correct shard context when #== is evaluated.
# File lib/octopus/scope_proxy.rb, line 61 def ==(other) method_missing(:==, other) end
Also aliased as: eql?
connection()
click to toggle source
# File lib/octopus/scope_proxy.rb, line 34 def connection @klass.connection_proxy.current_shard = @current_shard if @klass.custom_octopus_connection && @klass.allowed_shard?(@current_shard) # Force use of proxy, given we called 'using' explicitly to get here @klass.connection_proxy.current_model = @klass @klass.connection_proxy else @klass.connection end end
method_missing(method, *args, &block)
click to toggle source
# File lib/octopus/scope_proxy.rb, line 46 def method_missing(method, *args, &block) result = run_on_shard { @klass.__send__(method, *args, &block) } if result.respond_to?(:all) return ::Octopus::ScopeProxy.new(current_shard, result) end if result.respond_to?(:current_shard) result.current_shard = current_shard end result end
transaction(options = {}, &block)
click to toggle source
Transaction Method send all queries to a specified shard.
# File lib/octopus/scope_proxy.rb, line 30 def transaction(options = {}, &block) run_on_shard { @klass = klass.transaction(options, &block) } end
using(shard)
click to toggle source
# File lib/octopus/scope_proxy.rb, line 23 def using(shard) fail "Nonexistent Shard Name: #{shard}" if @klass.connection.shards[shard].nil? @current_shard = shard self end