Class: ChainGang::Proxy
- Inherits:
-
Object
show all
- Defined in:
- lib/chaingang/proxy.rb
Instance Method Summary
collapse
Constructor Details
#initialize(client) ⇒ Proxy
Returns a new instance of Proxy.
3
4
5
6
7
|
# File 'lib/chaingang/proxy.rb', line 3
def initialize(client)
@client = client
@params = {}
@find_scope = :all
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/chaingang/proxy.rb', line 24
def method_missing(method_name, *args, &block)
if args.length == 1
@params[method_name] = args.first
else
super method_name, *args, &block
end
self
end
|
Instance Method Details
#all ⇒ Object
12
|
# File 'lib/chaingang/proxy.rb', line 12
def all; @find_scope = :all; self; end
|
#and ⇒ Object
21
|
# File 'lib/chaingang/proxy.rb', line 21
def and; self; end
|
#each ⇒ Object
33
34
35
36
37
|
# File 'lib/chaingang/proxy.rb', line 33
def each
self.execute.each do |result|
yield result
end
end
|
#execute ⇒ Object
39
40
41
42
43
44
|
# File 'lib/chaingang/proxy.rb', line 39
def execute
options = {}
options[:from] = @from if @from
options[:params] = @params
@client.find_without_chaingang(@find_scope, options)
end
|
#first ⇒ Object
13
|
# File 'lib/chaingang/proxy.rb', line 13
def first; @find_scope = :first; self; end
|
#from(f) ⇒ Object
9
|
# File 'lib/chaingang/proxy.rb', line 9
def from(f); @from = f; self; end
|
#last ⇒ Object
14
|
# File 'lib/chaingang/proxy.rb', line 14
def last; @find_scope = :last; self; end
|
#one ⇒ Object
11
|
# File 'lib/chaingang/proxy.rb', line 11
def one; @find_scope = :one; self; end
|
#single(id) ⇒ Object
16
17
18
19
|
# File 'lib/chaingang/proxy.rb', line 16
def single(id)
@find_scope = id
self
end
|
#where ⇒ Object
22
|
# File 'lib/chaingang/proxy.rb', line 22
def where; self; end
|