1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Added self.inject_parameter_specs: this returns a block that is used to apply the service's parameter requirements to its Real implementation

This commit is contained in:
Juris Galang 2010-12-06 19:58:15 -08:00 committed by geemus
parent 634d1eb4f3
commit 6f187b2f72

View file

@ -18,6 +18,26 @@ module Fog
class << self
# this is to accomodate Real implementations of Service subclasses
# NOTE: it might be good to enforce parameter specs to Mock classes as well.
def inject_parameter_specs
lambda do |spec|
implementation = "Real"
self.const_set(implementation, Class.new) unless self.const_defined? implementation
realclass = self.const_get implementation
if realclass.declared_parameters_for(:'self.new', :required).empty?
required = declared_parameters_for(:'self.new', :required)
realclass.send(:requires, *required)
end
if realclass.declared_parameters_for(:'self.new', :optional).empty?
optional = declared_parameters_for(:'self.new', :optional)
realclass.send(:recognizes, *optional)
end
end
end
def inherited(child)
child.class_eval <<-EOS, __FILE__, __LINE__
module Collections
@ -35,7 +55,7 @@ module Fog
end
def requirements
declared_parameters_for :new, :required
declared_parameters_for :'self.new', :required
end
def new(options={})