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?(__DIR__) ||
|
||||||
$LOAD_PATH.include?(File.expand_path(__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
|
module Fog
|
||||||
|
|
||||||
class MockNotImplemented < StandardError; end
|
class MockNotImplemented < StandardError; end
|
||||||
|
|
||||||
def self.mock!
|
def self.mock!
|
||||||
@mocking = true
|
@mocking = true
|
||||||
self.reload
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.mocking?
|
def self.mocking?
|
||||||
!!@mocking
|
!!@mocking
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
Fog.dependencies.each {|dependency| require(dependency)}
|
|
||||||
|
|
|
@ -1,43 +1,25 @@
|
||||||
unless Fog.mocking?
|
module Fog
|
||||||
|
class Connection
|
||||||
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
|
|
||||||
|
|
||||||
|
def initialize(url)
|
||||||
|
@excon = Excon.new(url)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
else
|
def request(params)
|
||||||
|
if parser = params.delete(:parser)
|
||||||
module Fog
|
body = Nokogiri::XML::SAX::PushParser.new(parser)
|
||||||
class Connection
|
params[:block] = lambda { |chunk| body << chunk }
|
||||||
|
|
||||||
def initialize(url)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def request(params)
|
response = @excon.request(params)
|
||||||
|
|
||||||
|
if parser
|
||||||
|
body.finish
|
||||||
|
response.body = parser.response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
response
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue