Class: Commutator::Options::Proxy
- Inherits:
-
Object
- Object
- Commutator::Options::Proxy
show all
- Defined in:
- lib/commutator/options/proxy.rb
Defined Under Namespace
Classes: Operation
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context, callback_name) ⇒ Proxy
Returns a new instance of Proxy.
6
7
8
9
10
11
12
|
# File 'lib/commutator/options/proxy.rb', line 6
def initialize(context, callback_name)
@context = context
@callback_name = callback_name
@proxied_history = []
@options = instantiate_options
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/commutator/options/proxy.rb', line 31
def method_missing(method_name, *args, &block)
super unless options.respond_to?(method_name)
operation = Operation.new(method_name, args, block)
result = operation.apply(@options, @proxied_history)
result != options ? result : self
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4
5
6
|
# File 'lib/commutator/options/proxy.rb', line 4
def options
@options
end
|
#proxied_history ⇒ Object
Returns the value of attribute proxied_history.
4
5
6
|
# File 'lib/commutator/options/proxy.rb', line 4
def proxied_history
@proxied_history
end
|
Instance Method Details
#context(context) ⇒ Object
43
44
45
46
47
|
# File 'lib/commutator/options/proxy.rb', line 43
def context(context)
@context = context
@options = rehydrate_options
self
end
|
#count ⇒ Object
67
68
69
70
|
# File 'lib/commutator/options/proxy.rb', line 67
def count
response = @context.client.send(callback_name, options.dup.select("COUNT"))
response.inject(0) { |sum, page| sum + page.count }
end
|
#execute ⇒ Object
53
54
55
|
# File 'lib/commutator/options/proxy.rb', line 53
def execute
@context.send(callback_name, options)
end
|
#first ⇒ Object
57
58
59
60
|
# File 'lib/commutator/options/proxy.rb', line 57
def first
limit(1).asc.execute.items.first
end
|
#last ⇒ Object
62
63
64
65
|
# File 'lib/commutator/options/proxy.rb', line 62
def last
limit(1).desc.execute.items.first
end
|
#respond_to?(*args) ⇒ Boolean
39
40
41
|
# File 'lib/commutator/options/proxy.rb', line 39
def respond_to?(*args)
super || options.respond_to?(*args)
end
|