1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/service.rb
freeformz 30446e5ac1 Servicify & Hashify & more requests
Many changes:

-Become more of a proper Fog Service.
-Drop most of the Collection/Model customizations.
-Add a hook for services to do something after #new with the instance
-Move to the ToHashDocument parser ... so no more having to actually
make parsers.
-Fog::Vcloud::Extension is kind of like Fog::Service, but for writing
extension modules to Fog::Vcloud.
-Fix up existing specs/mocks (they're not complete atm, but the existing
ones are up to date).
-Fog::Vcloud::Terremark::Ecloud gets almost all extensions implemented
(almost).
-Fog::Vcloud::Terremark::Ecloud bumped to working with the current TMRK
API release.
-Factor out some TMRK/ecloud specifc mock data into the ecloud module.
-Probably forgetting something.
2010-06-28 02:10:27 +08:00

87 lines
1.9 KiB
Ruby

module Fog
module Service
def self.extended(other)
super
other.module_eval <<-EOS, __FILE__, __LINE__
class Error < Fog::Errors::Error; end
class NotFound < Fog::Errors::NotFound; end
module Collections; end
def self.new(options={})
missing = []
for requirement in requirements
missing << requirement unless options[requirement]
end
unless missing.empty?
if missing.length == 1
raise(ArgumentError, [missing.first, "is required for this service"].join(' '))
else
raise(ArgumentError, [missing[0...-1].join(", "), 'and', missing[-1], 'are required for this service'].join(' '))
end
end
unless @required
for model in models
require [@model_path, model].join('/')
end
for request in requests
require [@request_path, request].join('/')
end
@required = true
end
instance = if Fog.mocking?
Mock.new(options)
else
Real.new(options)
end
if self.respond_to?(:after_new)
instance = self.after_new(instance, options)
end
instance
end
EOS
end
def model_path(new_path)
@model_path = new_path
end
def model(new_model)
models << new_model
end
def models
@models ||= []
end
def request_path(new_path)
@request_path = new_path
end
def request(new_request)
requests << new_request
end
def requests
@requests ||= []
end
def requires(*args)
requirements.concat(args)
end
def requirements
@requirements ||= []
end
def reset_data(keys=Mock.data.keys)
Mock.reset_data(keys)
end
end
end