You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2010/07/09 01:43:12 UTC

svn commit: r962282 - /incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/features.rb

Author: lutter
Date: Thu Jul  8 23:43:12 2010
New Revision: 962282

URL: http://svn.apache.org/viewvc?rev=962282&view=rev
Log:
Features: allow modifying existing features and their operations

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/features.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/features.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/features.rb?rev=962282&r1=962281&r2=962282&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/features.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/base_driver/features.rb Thu Jul  8 23:43:12 2010
@@ -5,7 +5,6 @@ module Deltacloud
 
   class FeatureError < StandardError; end
   class DuplicateFeatureDeclError < FeatureError; end
-  class DuplicateFeatureError < FeatureError; end
   class UndeclaredFeatureError < FeatureError; end
 
   class BaseDriver
@@ -40,8 +39,15 @@ module Deltacloud
         @description
       end
 
+      # Add a new operation or modify an existing one through BLOCK
       def operation(name, &block)
-        @operations << Operation.new(name, &block)
+        unless op = @operations.find { |op| op.name == name }
+          op = Operation.new(name, &block)
+          @operations << op
+        else
+          op.instance_eval(&block) if block_given?
+        end
+        op
       end
     end
 
@@ -92,10 +98,14 @@ module Deltacloud
     end
 
     # Declare in a driver that it supports a specific feature
+    #
+    # The same feature can be declared multiple times in a driver, so that
+    # it can be changed successively by passing in different blocks.
     def self.feature(collection, name, &block)
       features[collection] ||= []
-      if features[collection].find { |f| f.name == name }
-        raise DuplicateFeatureError
+      if f = features[collection].find { |f| f.name == name }
+        f.instance_eval(&block) if block_given?
+        return f
       end
       unless decl = feature_decl_for(collection, name)
         raise UndeclaredFeatureError, "No feature #{name} for #{collection}"