Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added self.inject_parameter_specs: this returns a block that is used …
…to apply the service's parameter requirements to its Real implementation
  • Loading branch information
jurisgalang authored and geemus committed Dec 8, 2010
1 parent 634d1eb commit 6f187b2
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/fog/core/service.rb
Expand Up @@ -18,6 +18,26 @@ def requests

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
Expand All @@ -35,7 +55,7 @@ def self.service
end

def requirements
declared_parameters_for :new, :required
declared_parameters_for :'self.new', :required
end

def new(options={})
Expand Down

0 comments on commit 6f187b2

Please sign in to comment.