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:
parent
634d1eb4f3
commit
6f187b2f72
1 changed files with 21 additions and 1 deletions
|
@ -18,6 +18,26 @@ module Fog
|
||||||
|
|
||||||
class << self
|
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)
|
def inherited(child)
|
||||||
child.class_eval <<-EOS, __FILE__, __LINE__
|
child.class_eval <<-EOS, __FILE__, __LINE__
|
||||||
module Collections
|
module Collections
|
||||||
|
@ -35,7 +55,7 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
def requirements
|
def requirements
|
||||||
declared_parameters_for :new, :required
|
declared_parameters_for :'self.new', :required
|
||||||
end
|
end
|
||||||
|
|
||||||
def new(options={})
|
def new(options={})
|
||||||
|
|
Loading…
Reference in a new issue