Class: Layer::RelationProxy
- Inherits:
-
Object
- Object
- Layer::RelationProxy
show all
- Includes:
- Enumerable
- Defined in:
- lib/layer/relation_proxy.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(base, resource_type, operations = [], &block) ⇒ RelationProxy
Returns a new instance of RelationProxy.
7
8
9
10
11
12
13
14
|
# File 'lib/layer/relation_proxy.rb', line 7
def initialize(base, resource_type, operations = [], &block)
@resource_type = resource_type
@base = base
operations.each { |operation| singleton_class.send(:include, operation::ClassMethods) }
instance_eval(&block) if block_given?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/layer/relation_proxy.rb', line 34
def method_missing(method, *args, &block)
if resource_type.respond_to?(method)
resource_type.public_send(method, *args, &block)
else
super
end
end
|
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
5
6
7
|
# File 'lib/layer/relation_proxy.rb', line 5
def base
@base
end
|
#resource_type ⇒ Object
Returns the value of attribute resource_type.
5
6
7
|
# File 'lib/layer/relation_proxy.rb', line 5
def resource_type
@resource_type
end
|
Instance Method Details
#client ⇒ Object
24
25
26
|
# File 'lib/layer/relation_proxy.rb', line 24
def client
base.client
end
|
#each(&block) ⇒ Object
28
29
30
|
# File 'lib/layer/relation_proxy.rb', line 28
def each(&block)
all.each(&block)
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
20
21
22
|
# File 'lib/layer/relation_proxy.rb', line 20
def respond_to_missing?(method, include_private = false)
resource_type.respond_to?(method, include_private) || super
end
|
#url ⇒ Object
16
17
18
|
# File 'lib/layer/relation_proxy.rb', line 16
def url
"#{base.url}#{resource_type.url}"
end
|