Class: PathTo::Path
- Inherits:
-
WithParams
- Object
- WithParams
- PathTo::Path
- Defined in:
- lib/path-to/path.rb
Overview
Builds on the chaining and param collection of WithParams to provide chainable references to URIs. Delegates the modelling of the web application to a parent (or ancestor) application object, so that this configuration is in one place (and perhaps the result of a discovery process).
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from WithParams
Instance Method Summary collapse
-
#application ⇒ Object
Finds (and remembers) the application in the parent hierarchy.
-
#child_class_for(instance, service, args) ⇒ Object
Delegated to the application object (see Application#child_class_for for details).
-
#delete(*args) ⇒ Object
DELETE request on this object’s URI.
-
#get(*args) ⇒ Object
GET request on this object’s URI.
-
#http_client ⇒ Object
Returns the http_client of the application; override if necessary.
-
#inspect ⇒ Object
:nodoc:.
-
#merge_http_options(args) ⇒ Object
Include application.http_options (if exists) in args, either appending it or reverse-merging with the last element of args if it’s a Hash.
-
#post(*args) ⇒ Object
POST request on this object’s URI.
-
#put(*args) ⇒ Object
PUT request on this object’s URI.
-
#uri ⇒ Object
Generate a URI for this object, using application.uri_for (see Application#uri_for for details).
-
#uri_template ⇒ Object
Generate a URI for this object, using application.uri_for (see Application#uri_for for details).
Methods inherited from WithParams
#[], #child, #complete_params_hash!, #extract_params, #initialize, #method_missing, #respond_to?
Constructor Details
This class inherits a constructor from PathTo::WithParams
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class PathTo::WithParams
Instance Method Details
#application ⇒ Object
Finds (and remembers) the application in the parent hierarchy.
13 14 15 |
# File 'lib/path-to/path.rb', line 13 def application @application ||= parent.application if parent end |
#child_class_for(instance, service, args) ⇒ Object
Delegated to the application object (see Application#child_class_for for details).
20 21 22 |
# File 'lib/path-to/path.rb', line 20 def child_class_for(instance, service, args) application.child_class_for(instance, service, args) end |
#delete(*args) ⇒ Object
DELETE request on this object’s URI
68 69 70 |
# File 'lib/path-to/path.rb', line 68 def delete(*args) http_client.delete(uri, *(args)) end |
#get(*args) ⇒ Object
GET request on this object’s URI
47 48 49 |
# File 'lib/path-to/path.rb', line 47 def get(*args) http_client.get(uri, *(args)) end |
#http_client ⇒ Object
Returns the http_client of the application; override if necessary. See also HTTPClient.
27 28 29 |
# File 'lib/path-to/path.rb', line 27 def http_client @http_client ||= application.http_client end |
#inspect ⇒ Object
:nodoc:
87 88 89 |
# File 'lib/path-to/path.rb', line 87 def inspect #:nodoc: "#{uri} #<#{self.class.name}:#{"0x%x" % object_id} service=#{service.inspect}, params=#{params.inspect}>" end |
#merge_http_options(args) ⇒ Object
Include application.http_options (if exists) in args, either appending it or reverse-merging with the last element of args if it’s a Hash
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/path-to/path.rb', line 75 def (args) if ( = application.) if args[-1].kind_of?(Hash) args[-1] = .merge(args[-1]) else args << end end args end |
#post(*args) ⇒ Object
POST request on this object’s URI
61 62 63 |
# File 'lib/path-to/path.rb', line 61 def post(*args) http_client.post(uri, *(args)) end |
#put(*args) ⇒ Object
PUT request on this object’s URI
54 55 56 |
# File 'lib/path-to/path.rb', line 54 def put(*args) http_client.put(uri, *(args)) end |
#uri ⇒ Object
Generate a URI for this object, using application.uri_for (see Application#uri_for for details).
34 35 36 |
# File 'lib/path-to/path.rb', line 34 def uri application.uri_for(service, params) end |
#uri_template ⇒ Object
Generate a URI for this object, using application.uri_for (see Application#uri_for for details).
41 42 43 |
# File 'lib/path-to/path.rb', line 41 def uri_template application.uri_template_for(self, service, params) end |