Class: ContextIO::Lite::URLBuilder
- Inherits:
-
Object
- Object
- ContextIO::Lite::URLBuilder
- Defined in:
- lib/contextio/lite/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.
- .uri_encode(param) ⇒ Object
-
.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.
39 40 41 42 |
# File 'lib/contextio/lite/url_builder.rb', line 39 def self.register_url(resource_class, &block) @registered_urls ||= {} @registered_urls[resource_class] = block end |
.uri_encode(param) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/contextio/lite/url_builder.rb', line 85 def self.uri_encode(param) if param.is_a? String URI.encode param else param end end |
.url_for(resource) ⇒ String
Tells you the right URL for a resource to fetch attributes from.
18 19 20 21 22 23 24 |
# File 'lib/contextio/lite/url_builder.rb', line 18 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 |