Class: Twelve::ResourceProxy
- Inherits:
-
Object
- Object
- Twelve::ResourceProxy
- 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
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Make connection and path_prefix readable.
-
#connection ⇒ Object
readonly
Make connection and path_prefix readable.
-
#path_prefix ⇒ Object
readonly
Make connection and path_prefix readable.
Instance Method Summary collapse
-
#initialize(connection, path_prefix, attributes = nil) ⇒ ResourceProxy
constructor
Instantiates proxy with the connection and path_prefix.
-
#method_missing(message, *args) ⇒ Object
Method_missing takes any message passed to the ResourceProxy and sends it to the real object.
-
#subject ⇒ Object
Subject is the response body parsed as json.
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(, *args) subject.send(, *args) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Make connection and path_prefix readable
14 15 16 |
# File 'lib/twelve/resource_proxy.rb', line 14 def attributes @attributes end |
#connection ⇒ Object (readonly)
Make connection and path_prefix readable
14 15 16 |
# File 'lib/twelve/resource_proxy.rb', line 14 def connection @connection end |
#path_prefix ⇒ Object (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
#subject ⇒ Object
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 |