Class: ContextIO::API::URLBuilder
- Inherits:
-
Object
- Object
- ContextIO::API::URLBuilder
- Defined in:
- lib/contextio/api/url_builder.rb
Defined Under Namespace
Classes: Error
Class Method Summary collapse
-
.register_url(resource_class, &block) ⇒ Object
Register a block that calculates the URL for a given resource.
-
.url_for(resource) ⇒ String
Tells you the right URL for a resource to fetch attributes from.
Class Method Details
.register_url(resource_class, &block) ⇒ Object
Register a block that calculates the URL for a given resource.
47 48 49 50 |
# File 'lib/contextio/api/url_builder.rb', line 47 def self.register_url(resource_class, &block) @registered_urls ||= {} @registered_urls[resource_class] = block end |
.url_for(resource) ⇒ String
Tells you the right URL for a resource to fetch attributes from.
26 27 28 29 30 31 32 |
# File 'lib/contextio/api/url_builder.rb', line 26 def self.url_for(resource) if (builder = @registered_urls[resource.class]) builder.call(resource) else raise Error, "URL could not be built for unregistered Class: #{resource.class}." end end |