Skip to content

Instantly share code, notes, and snippets.

@tobias
Created November 3, 2010 14:40
Show Gist options
  • Save tobias/661145 to your computer and use it in GitHub Desktop.
Save tobias/661145 to your computer and use it in GitHub Desktop.
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