Class: Hyperclient::ResourceFactory
- Inherits:
-
Object
- Object
- Hyperclient::ResourceFactory
- Defined in:
- lib/hyperclient/resource_factory.rb
Overview
This class acts as an interface to build Resources. It has a simple identity map so a user can save HTTP calls when interacting with the same resource.
Class Method Summary collapse
-
.identity_map ⇒ Object
private
private
Returns a Hash that acts as identity map.
-
.resource(url, *args) ⇒ Object
A factory method to build Resources.
Class Method Details
.identity_map ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a Hash that acts as identity map.
27 28 29 |
# File 'lib/hyperclient/resource_factory.rb', line 27 def self.identity_map @identity_map ||= {} end |
.resource(url, *args) ⇒ Object
A factory method to build Resources. It will try to find a Resource in the identity map or build a new one if does not exist.
17 18 19 20 21 22 23 |
# File 'lib/hyperclient/resource_factory.rb', line 17 def self.resource(url, *args) identity_map.fetch(url) do |url| resource = Resource.new(url, *args) identity_map.update(url => resource) resource end end |