Class: XBar::ScopeProxy
- Inherits:
-
Object
- Object
- XBar::ScopeProxy
- Defined in:
- lib/xbar/scope_proxy.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#shard ⇒ Object
Returns the value of attribute shard.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #connection ⇒ Object
-
#initialize(shard, klass) ⇒ ScopeProxy
constructor
A new instance of ScopeProxy.
- #method_missing(method, *args, &block) ⇒ Object
-
#transaction(options = {}, &block) ⇒ Object
Transaction Method send all queries to a specified shard.
- #using(shard) ⇒ Object
Constructor Details
#initialize(shard, klass) ⇒ ScopeProxy
Returns a new instance of ScopeProxy.
4 5 6 7 |
# File 'lib/xbar/scope_proxy.rb', line 4 def initialize(shard, klass) @shard = shard @klass = klass end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/xbar/scope_proxy.rb', line 29 def method_missing(method, *args, &block) @klass.connection.current_model = @klass # XXX if XBar.debug # puts "Connection proxy klass proxy is #{@klass.connection.class.name}" # puts "Scope proxy assigned current_model #{@klass.name}" # puts "Block given is #{block_given?}" end @klass.connection.run_queries_on_shard(@shard, true) do #puts "ScopeProxy, method missing, sending query to shard: #{@shard}, klass is #{@klass}" #puts "ScropeProxy, has response: method = #{method.to_s}, #{@klass.respond_to? method}" # puts Thread.current.backtrace #puts "ScopeProxy, connection class = #{@klass.connection.class.name}" @klass = @klass.send(method, *args, &block) #puts "After invocation..." end return @klass if @klass.is_a?(ActiveRecord::Base) or @klass.is_a?(Array) or @klass.is_a?(Fixnum) or @klass.nil? return self end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
2 3 4 |
# File 'lib/xbar/scope_proxy.rb', line 2 def klass @klass end |
#shard ⇒ Object
Returns the value of attribute shard.
2 3 4 |
# File 'lib/xbar/scope_proxy.rb', line 2 def shard @shard end |
Instance Method Details
#==(other) ⇒ Object
51 52 53 54 |
# File 'lib/xbar/scope_proxy.rb', line 51 def ==(other) @shard == other.shard @klass == other.klass end |
#connection ⇒ Object
24 25 26 27 |
# File 'lib/xbar/scope_proxy.rb', line 24 def connection @klass.connection.current_shard = @shard @klass.connection end |
#transaction(options = {}, &block) ⇒ Object
Transaction Method send all queries to a specified shard.
18 19 20 21 22 |
# File 'lib/xbar/scope_proxy.rb', line 18 def transaction( = {}, &block) @klass.connection.run_queries_on_shard(@shard) do @klass = @klass.connection.transaction(, &block) end end |
#using(shard) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/xbar/scope_proxy.rb', line 9 def using(shard) unless @klass.connection.shards[shard] raise "Nonexistent Shard Name: #{shard}" end @shard = shard return self end |