Class: Twelve::ResourceProxy

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

Overview

ResourceProxy lets us create a virtual proxy for any API resource, utilizing method_missing to handle passing messages to the real object

Direct Known Subclasses

API::Clients::Proxy, API::Gauges::Proxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, path_prefix, attributes = nil) ⇒ ResourceProxy

Instantiates proxy with the connection and path_prefix

connection - Twelve::Connection object path_prefix - String



22
23
24
# File 'lib/twelve/resource_proxy.rb', line 22

def initialize(connection, path_prefix, attributes=nil)
  @connection, @path_prefix, @attributes = connection, path_prefix, attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(message, *args) ⇒ Object

Method_missing takes any message passed to the ResourceProxy and sends it to the real object

message - Message object args* - Arguements passed



33
34
35
# File 'lib/twelve/resource_proxy.rb', line 33

def method_missing(message, *args)
  subject.send(message, *args)
end

Instance Attribute Details

#attributesObject (readonly)

Make connection and path_prefix readable



14
15
16
# File 'lib/twelve/resource_proxy.rb', line 14

def attributes
  @attributes
end

#connectionObject (readonly)

Make connection and path_prefix readable



14
15
16
# File 'lib/twelve/resource_proxy.rb', line 14

def connection
  @connection
end

#path_prefixObject (readonly)

Make connection and path_prefix readable



14
15
16
# File 'lib/twelve/resource_proxy.rb', line 14

def path_prefix
  @path_prefix
end

Instance Method Details

#subjectObject

Subject is the response body parsed as json

Returns json



42
43
44
# File 'lib/twelve/resource_proxy.rb', line 42

def subject
  raise "Implement in Proxy class for resource"
end