Class: PathTo::Path

Inherits:
WithParams show all
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

DescribedRoutes::TemplatedPath

Instance Attribute Summary

Attributes inherited from WithParams

#params, #parent, #service

Instance Method Summary collapse

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

#applicationObject

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, *merge_http_options(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, *merge_http_options(args))
end

#http_clientObject

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

#inspectObject

: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 merge_http_options(args)
  if (http_options = application.http_options)
    if args[-1].kind_of?(Hash)
      args[-1] = http_options.merge(args[-1])
    else
      args << http_options
    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, *merge_http_options(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, *merge_http_options(args))
end

#uriObject

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_templateObject

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