Created
November 3, 2010 14:40
-
-
Save tobias/661145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def control(opts=nil, &block) | |
op = self | |
@control = Proc.new do | |
if opts and | |
opts[:with_capability] and | |
!driver.respond_to?(opts[:with_capability]) | |
raise Deltacloud::BackendFeatureUnsupported.new('501', nil, | |
"#{opts[:with_capability]} not supported by backend", nil) | |
end | |
op.validate(params) | |
instance_eval(&block) | |
end | |
end | |
#this: | |
operation :destroy do | |
description "Destroy given instance credential if backend supports this." | |
param :id, :string, :required | |
control do | |
unless driver.respond_to?(:destroy_key) | |
raise Deltacloud::BackendFeatureUnsupported.new('501', | |
'Creating instance credentials is not supported in backend') | |
end | |
driver.destroy_key(credentials, { :key_name => params[:id]}) | |
redirect(keys_url) | |
end | |
end | |
#becomes this: | |
operation :destroy do | |
description "Destroy given instance credential if backend supports this." | |
param :id, :string, :required | |
control(:with_capability => :destroy_key) do | |
driver.destroy_key(credentials, { :key_name => params[:id]}) | |
redirect(keys_url) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment