You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2013/03/01 10:43:48 UTC

[2/2] git commit: Core: Added possibility to run filter_on with multiple attrs

Updated Branches:
  refs/heads/master 6275a4d8e -> 868aa52a4


Core: Added possibility to run filter_on with multiple attrs

So instead of writing:

instances = filter_on instances, :id, opts
instances = filter_on instances, :realm_id, opts
instances = filter_on instances, :state, opts

You can now use:

instances = filter_on instances, opts, :id, :realm_id, :state

The backward compatibility with old filter_on included.


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/819ac06b
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/819ac06b
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/819ac06b

Branch: refs/heads/master
Commit: 819ac06b53a25ff011795e40616b2cd3b1205ebf
Parents: 6275a4d
Author: Michal Fojtik <mf...@redhat.com>
Authored: Mon Feb 18 14:23:37 2013 +0100
Committer: Michal fojtik <mf...@redhat.com>
Committed: Fri Mar 1 10:40:16 2013 +0100

----------------------------------------------------------------------
 server/lib/deltacloud/drivers/base_driver.rb |   27 +++++++++++++++-----
 1 files changed, 20 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/819ac06b/server/lib/deltacloud/drivers/base_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index e346e7c..2b8866c 100644
--- a/server/lib/deltacloud/drivers/base_driver.rb
+++ b/server/lib/deltacloud/drivers/base_driver.rb
@@ -262,14 +262,27 @@ module Deltacloud
     MEMBER_SHOW_METHODS = [ :realm, :image, :instance, :storage_volume, :bucket, :blob,
                             :key, :firewall ] unless defined?(MEMBER_SHOW_METHODS)
 
-    def filter_on(collection, attribute, opts)
+    def filter_on(collection, opts, *attributes)
+      opts, attributes = attributes.pop, [opts] if !opts.nil? and !(opts.is_a?(Hash))
+      # FIXME: ^^ This is just to keep backward compatibility until
+      # drivers will be fixed to use the new syntax.
+      #
+      # filter_on instances, :opts, [ :id, :state, :realm_id]
+      #
+      # instead of old:
+      #
+      # filter_on instances, :id, opts
+      # filter_on instances, :state, opts
+      # filter_on instances, :realm_id, opts
+
       return collection if opts.nil?
-      return collection if opts[attribute].nil?
-      filter = opts[attribute]
-      if ( filter.is_a?( Array ) )
-        return collection.select{|e| filter.include?( e.send(attribute) ) }
-      else
-        return collection.select{|e| filter == e.send(attribute) }
+      attributes.each do |attribute|
+        next unless filter = opts[attribute]
+        if ( filter.is_a?( Array ) )
+          collection.select! { |e| filter.include?( e.send(attribute) ) }
+        else
+          collection.select! { |e| filter == e.send(attribute) }
+        end
       end
     end