deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 3/6] Client: Added object_ids method which return an Array with collection members ids (instance_ids, realm_ids, etc.)
Date Tue, 24 Jan 2012 11:31:11 GMT
From: Michal Fojtik <mfojtik@redhat.com>

Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 client/lib/deltacloud.rb |    5 ++++-
 client/lib/string.rb     |    9 +++++++++
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index b782509..6fec8bb 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -280,7 +280,10 @@ module DeltaCloud
     # Generate create_* methods dynamically
     #
     def method_missing(name, *args)
-      if name.to_s =~ /create_(\w+)/
+      if name.to_s =~ /^([\w_]+)_ids$/
+        return self.send(:"#{$1.pluralize}").map { |o| o.id }
+      end
+      if name.to_s =~ /^create_(\w+)/
         params = args[0] if args[0] and args[0].class.eql?(Hash)
         params ||= args[1] if args[1] and args[1].class.eql?(Hash)
         params ||= {}
diff --git a/client/lib/string.rb b/client/lib/string.rb
index 00e2cde..fb90564 100644
--- a/client/lib/string.rb
+++ b/client/lib/string.rb
@@ -36,6 +36,15 @@ class String
     end
   end
 
+  unless method_defined?(:pluralize)
+    def pluralize
+      return self + 'es' if self =~ /ess$/
+      return self[0, self.length-1] + "ies" if self =~ /ty$/
+      return self if self =~ /data$/
+      self + "s"
+    end
+  end
+
   # Convert string to float if string value seems like Float
   def convert
     return self.to_f if self.strip =~ /^([\d\.]+$)/
-- 
1.7.4.4


Mime
View raw message