class ActiveRacksource #:nodoc:
# Overrides parts of ActiveResource::Connection for ActiveRacksource (to use Rack instead of HTTP)
module Connection
def self.included base
base.instance_eval {
alias_method_chain :http, :rack_instead_of_real_http
}
end
# Overrides ActiveResource::Connection#http, returning our own object
# that uses a Rack application instead of actually going over HTTP
#
# example of what the HTTP object might get sent:
# http.send( :get, "/dogs.xml", [{"Accept"=>"application/xml"}] )
# http.send( :post, "/dogs.xml", ["\n\n Rover\n\n", {"Content-Type"=>"application/xml"}])
# http.send( :delete, "/dogs/6.xml", [{"Accept"=>"application/xml"}])
# http.send( :put, "/dogs/1.xml", ["\n\n spot\n 2009-02-09T18:27:11Z\n 2009-02-09T18:27:11Z\n 1\n\n", {"Content-Type"=>"application/xml"}])
#
# the object http.send :foo returns should have
# #code: string representation of status code, eg. '200' or '404'
# #message: string message, eg. 'OK' or 'Not Found'
# #body: string response body
#
def http_with_rack_instead_of_real_http
if ActiveResource::Base.app
ActiveRacksource::HTTP.new ActiveResource::Base.app
else
http_without_rack_instead_of_real_http
end
end
end
end