mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
fix top level mocking related setup
This commit is contained in:
parent
c540fba1fa
commit
9c5460c77b
2 changed files with 24 additions and 53 deletions
29
lib/fog.rb
29
lib/fog.rb
|
@ -17,36 +17,25 @@ $LOAD_PATH.unshift __DIR__ unless
|
|||
$LOAD_PATH.include?(__DIR__) ||
|
||||
$LOAD_PATH.include?(File.expand_path(__DIR__))
|
||||
|
||||
require 'fog/collection'
|
||||
require 'fog/connection'
|
||||
require 'fog/model'
|
||||
require 'fog/parser'
|
||||
require 'fog/aws'
|
||||
require 'fog/rackspace'
|
||||
require 'fog/slicehost'
|
||||
require 'fog/terremark'
|
||||
|
||||
module Fog
|
||||
|
||||
class MockNotImplemented < StandardError; end
|
||||
|
||||
def self.mock!
|
||||
@mocking = true
|
||||
self.reload
|
||||
end
|
||||
|
||||
def self.mocking?
|
||||
!!@mocking
|
||||
end
|
||||
|
||||
def self.dependencies
|
||||
[
|
||||
'fog/collection.rb',
|
||||
'fog/connection.rb',
|
||||
'fog/model.rb',
|
||||
'fog/parser.rb',
|
||||
'fog/aws.rb',
|
||||
'fog/rackspace.rb',
|
||||
'fog/slicehost.rb',
|
||||
'fog/terremark.rb'
|
||||
]
|
||||
end
|
||||
|
||||
def self.reload
|
||||
self.dependencies.each {|dependency| load(dependency)}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Fog.dependencies.each {|dependency| require(dependency)}
|
||||
|
|
|
@ -1,43 +1,25 @@
|
|||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
class Connection
|
||||
|
||||
def initialize(url)
|
||||
@excon = Excon.new(url)
|
||||
end
|
||||
|
||||
def request(params)
|
||||
if parser = params.delete(:parser)
|
||||
body = Nokogiri::XML::SAX::PushParser.new(parser)
|
||||
params[:block] = lambda { |chunk| body << chunk }
|
||||
end
|
||||
|
||||
response = @excon.request(params)
|
||||
|
||||
if parser
|
||||
body.finish
|
||||
response.body = parser.response
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
module Fog
|
||||
class Connection
|
||||
|
||||
def initialize(url)
|
||||
@excon = Excon.new(url)
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
class Connection
|
||||
|
||||
def initialize(url)
|
||||
def request(params)
|
||||
if parser = params.delete(:parser)
|
||||
body = Nokogiri::XML::SAX::PushParser.new(parser)
|
||||
params[:block] = lambda { |chunk| body << chunk }
|
||||
end
|
||||
|
||||
def request(params)
|
||||
response = @excon.request(params)
|
||||
|
||||
if parser
|
||||
body.finish
|
||||
response.body = parser.response
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue