Module: Arke::Resource::URL::ClassMethods
- Defined in:
- lib/arke/resource/url.rb
Instance Method Summary collapse
-
#endpoint(endpoint = nil) ⇒ String
Gets or sets the device endpoint.
-
#host(host = nil) ⇒ String
Gets or sets the resource host.
-
#url(options = {}) ⇒ String
Gets the resource url.
-
#url_template(template = nil) ⇒ Addressable::Template
Gets or sets the url template for the resource.
Instance Method Details
#endpoint(endpoint = nil) ⇒ String
Gets or sets the device endpoint. By default the endpoint uses #resource_name if an endpoint has not been provided.
54 55 56 57 |
# File 'lib/arke/resource/url.rb', line 54 def endpoint(endpoint=nil) @endpoint = endpoint if endpoint @endpoint ||= resource_name end |
#host(host = nil) ⇒ String
Gets or sets the resource host.
30 31 32 33 |
# File 'lib/arke/resource/url.rb', line 30 def host(host=nil) @host = host if host @host end |
#url(options = {}) ⇒ String
Gets the resource url. This compiles the url template using the passed options and returns the resulting string.
query.
42 43 44 45 46 |
# File 'lib/arke/resource/url.rb', line 42 def url(={}) template = [:_template] ? Addressable::Template.new(.delete(:_template)) : nil ||self.url_template = {parent_resource_name: .delete(:_parent_resource_name), relation_id: .delete(:_relation_id), resource_name: .delete(:_resource_name)} host + template.(.merge(.merge(endpoint: endpoint))).to_s end |
#url_template(template = nil) ⇒ Addressable::Template
Gets or sets the url template for the resource. The url template is a Addressable template and defaults to DEFAULT_URL_TEMPLATE. If a parameter is passed to this method it will set the url template to the passed parameter, otherwise it will just return the URL template.
url template
20 21 22 23 |
# File 'lib/arke/resource/url.rb', line 20 def url_template(template=nil) @url_template = Addressable::Template.new(template) if template @url_template || Addressable::Template.new(DEFAULT_URL_TEMPLATE) end |