Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make it easier to switch between mocked and real requests

  • Loading branch information...
commit 8111505b1963e271fd56dd35f551150ce8d383a0 1 parent e75d521
@jweiss authored
View
24 lib/rocking_chair.rb
@@ -16,31 +16,31 @@
require "rocking_chair/database"
require "rocking_chair/server"
require "rocking_chair/couch_rest_http_adapter"
+require "rocking_chair/http_adapter"
+
module RockingChair
-
- @_rocking_chair_enabled
+
+ @_rocking_chair_enabled = false
def self.enable
- unless @_rocking_chair_enabled
- HttpAbstraction.extend(RockingChair::CouchRestHttpAdapter)
- @_rocking_chair_enabled = true
- end
+ @_rocking_chair_enabled = true
end
def self.disable
- if @_rocking_chair_enabled
- HttpAbstraction.extend(RestClientAdapter::API)
- @_rocking_chair_enabled = false
- end
+ @_rocking_chair_enabled = false
+ end
+
+ def self.enabled?
+ @_rocking_chair_enabled
end
def self.enable_debug
- HttpAbstraction.instance_variable_set("@_rocking_chair_debug", true)
+ RockingChair::CouchRestHttpAdapter.instance_variable_set("@_rocking_chair_debug", true)
end
def self.disable_debug
- HttpAbstraction.instance_variable_set("@_rocking_chair_debug", false)
+ RockingChair::CouchRestHttpAdapter.instance_variable_set("@_rocking_chair_debug", false)
end
end
View
10 lib/rocking_chair/couch_rest_http_adapter.rb
@@ -4,7 +4,7 @@ module CouchRestHttpAdapter
@_rocking_chair_debug = false
- def get(uri, headers={})
+ def self.get(uri, headers={})
puts "GET: #{uri.inspect}: #{headers.inspect}" if @_rocking_chair_debug
url, parameters = RockingChair::Server.normalize_url(uri)
if url == ''
@@ -28,7 +28,7 @@ def get(uri, headers={})
end
end
- def post(uri, payload, headers={})
+ def self.post(uri, payload, headers={})
puts "POST: #{uri.inspect}: #{payload.inspect} #{headers.inspect}" if @_rocking_chair_debug
url, parameters = RockingChair::Server.normalize_url(uri)
if url.match(/\A(#{URL_PARAMETER})\/?\Z/)
@@ -40,7 +40,7 @@ def post(uri, payload, headers={})
end
end
- def put(uri, payload, headers={})
+ def self.put(uri, payload, headers={})
puts "PUT: #{uri.inspect}: #{payload.inspect} #{headers.inspect}" if @_rocking_chair_debug
url, parameters = RockingChair::Server.normalize_url(uri)
if url.match(/\A(#{URL_PARAMETER})\Z/)
@@ -54,7 +54,7 @@ def put(uri, payload, headers={})
end
end
- def delete(uri, headers={})
+ def self.delete(uri, headers={})
puts "DELETE: #{uri.inspect}: #{headers.inspect}" if @_rocking_chair_debug
url, parameters = RockingChair::Server.normalize_url(uri)
if url.match(/\A(#{URL_PARAMETER})\Z/)
@@ -68,7 +68,7 @@ def delete(uri, headers={})
end
end
- def copy(uri, headers)
+ def self.copy(uri, headers)
puts "COPY: #{uri.inspect}: #{headers.inspect}" if @_rocking_chair_debug
url, parameters = RockingChair::Server.normalize_url(uri)
if url.match(/\A(#{URL_PARAMETER})\/(#{URL_PARAMETER})\Z/)
View
35 lib/rocking_chair/http_adapter.rb
@@ -0,0 +1,35 @@
+module RockingChair
+ module HttpAdapter
+
+ def http_adapter
+ if RockingChair.enabled?
+ RockingChair::CouchRestHttpAdapter
+ else
+ RestClientAdapter::API
+ end
+ end
+
+ def get(uri, headers=nil)
+ http_adapter.get(uri, headers)
+ end
+
+ def post(uri, payload, headers=nil)
+ http_adapter.post(uri, payload, headers)
+ end
+
+ def put(uri, payload, headers=nil)
+ http_adapter.put(uri, payload, headers)
+ end
+
+ def delete(uri, headers=nil)
+ http_adapter.delete(uri, headers)
+ end
+
+ def copy(uri, headers)
+ http_adapter.copy(uri, headers)
+ end
+
+ end
+end
+
+HttpAbstraction.extend(RockingChair::HttpAdapter)
Please sign in to comment.
Something went wrong with that request. Please try again.