Class: Tako::QueryChain

Inherits:
Object
  • Object
show all
Defined in:
lib/tako/query_chain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proxy, base_object) ⇒ QueryChain

Returns a new instance of QueryChain.



6
7
8
9
# File 'lib/tako/query_chain.rb', line 6

def initialize(proxy, base_object)
  @proxy = proxy
  @base_object = base_object
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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

Instance Attribute Details

#base_objectObject (readonly)

Returns the value of attribute base_object.



4
5
6
# File 'lib/tako/query_chain.rb', line 4

def base_object
  @base_object
end

#proxyObject (readonly)

Returns the value of attribute proxy.



3
4
5
# File 'lib/tako/query_chain.rb', line 3

def proxy
  @proxy
end

Instance Method Details

#shard(shard_name) ⇒ Object



28
29
30
31
32
33
# File 'lib/tako/query_chain.rb', line 28

def shard(shard_name)
  new(
    Tako::Repository.create_proxy(shard_name),
    self
  )
end