Class: Layer::ResourceProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/layer/resource_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, base, resource) ⇒ ResourceProxy

Returns a new instance of ResourceProxy.



5
6
7
8
9
10
# File 'lib/layer/resource_proxy.rb', line 5

def initialize(client, base, resource)
  @client = client
  @base = base
  @resource = resource
  @url = get_url(base, resource)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



16
17
18
# File 'lib/layer/resource_proxy.rb', line 16

def method_missing(method, *args, &block)
  @resource.public_send(method, *([@client, @url] + args), &block)
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/layer/resource_proxy.rb', line 3

def url
  @url
end

Instance Method Details

#get_url(base, resource) ⇒ Object



12
13
14
# File 'lib/layer/resource_proxy.rb', line 12

def get_url(base, resource)
  base.nil? ? resource.url : "#{base.url}/#{resource.url}"
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/layer/resource_proxy.rb', line 20

def respond_to_missing?(method, include_private = false)
  @resource.respond_to?(method) || super
end