class Tako::QueryChain

Attributes

base_object[R]
proxy[R]

Public Class Methods

new(proxy, base_object) click to toggle source
# File lib/tako/query_chain.rb, line 6
def initialize(proxy, base_object)
  @proxy = proxy
  @base_object = base_object
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source
# File lib/tako/query_chain.rb, line 11
def method_missing(method, *args, &block)
  @proxy.with_shard do
    result = if block_given?
                base_object.send(method, *args, &block)
              else
                base_object.send(method, *args)
              end

    if chain_available?(result)
      @base_object = result
      return self
    end

    result
  end
end
shard(shard_name) click to toggle source
# File lib/tako/query_chain.rb, line 28
def shard(shard_name)
  new(
    Tako::Repository.create_proxy(shard_name),
    self
  )
end

Private Instance Methods

chain_available?(obj) click to toggle source
# File lib/tako/query_chain.rb, line 37
def chain_available?(obj)
  [
    ::ActiveRecord::Relation,
    ::ActiveRecord::QueryMethods::WhereChain
  ].any? { |anc| obj.is_a?(anc) }
end