Class: DataMapperRest::Connection
- Inherits:
-
Object
- Object
- DataMapperRest::Connection
- Defined in:
- lib/dm-rest-adapter/connection.rb
Overview
Somewhat stolen from ActiveResource TODO: Support https?
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(uri, format) ⇒ Connection
constructor
A new instance of Connection.
-
#method_missing(method, *args) ⇒ Object
this is used to run the http verbs like http_post, http_put, http_delete etc.
Constructor Details
#initialize(uri, format) ⇒ Connection
Returns a new instance of Connection.
9 10 11 12 |
# File 'lib/dm-rest-adapter/connection.rb', line 9 def initialize(uri, format) @uri = uri @format = Format.new(format) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
this is used to run the http verbs like http_post, http_put, http_delete etc. TODO: handle nested resources, see prefix in ActiveResource
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dm-rest-adapter/connection.rb', line 16 def method_missing(method, *args) if verb = method.to_s.match(/\Ahttp_(get|post|put|delete|head)\z/) orig_uri, @uri = @uri, @uri.dup begin path, query = args[0].split('?', 2) @uri.path = "#{path}.#{@format.extension}#{'?' << query if query}" # Should be the form of /resources run_verb(verb.to_s.split('_').last, args[1]) ensure @uri = orig_uri end end end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
7 8 9 |
# File 'lib/dm-rest-adapter/connection.rb', line 7 def format @format end |
#uri ⇒ Object
Returns the value of attribute uri.
7 8 9 |
# File 'lib/dm-rest-adapter/connection.rb', line 7 def uri @uri end |