deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [07/14] git commit: Network API rev 3 - Collection helpers (passing context to views - check for presence of resource)
Date Fri, 26 Apr 2013 15:47:04 GMT
Network API rev 3 - Collection helpers (passing context to views - check for presence of resource)


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

Branch: refs/heads/master
Commit: 483be9a49ea1d14371f292a17363cfdb1a7a7c29
Parents: 895a9c6
Author: marios <marios@redhat.com>
Authored: Fri Apr 12 12:11:04 2013 +0300
Committer: marios <marios@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300

----------------------------------------------------------------------
 server/lib/deltacloud/helpers/deltacloud_helper.rb |   15 +++++++++------
 server/lib/deltacloud/helpers/rabbit_helper.rb     |    8 ++++----
 2 files changed, 13 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/483be9a4/server/lib/deltacloud/helpers/deltacloud_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/deltacloud_helper.rb b/server/lib/deltacloud/helpers/deltacloud_helper.rb
index e069312..242effc 100644
--- a/server/lib/deltacloud/helpers/deltacloud_helper.rb
+++ b/server/lib/deltacloud/helpers/deltacloud_helper.rb
@@ -65,18 +65,19 @@ module Deltacloud::Helpers
       http_method || Deltacloud::Rabbit::BaseCollection.http_method_for(action)
     end
 
-    def filter_all(model)
+    def filter_all(model, opts={})
       begin
         @benchmark = Benchmark.measure { @elements = driver.send(model.to_sym, credentials,
params) }
       rescue => e
         @exception = e
       end
+      locals = opts[:check] ? {:elements => @elements, opts[:check]=>driver.respond_to?(opts[:check])}
: {:elements => @elements}
       if @elements
         headers['X-Backend-Runtime'] = @benchmark.real.to_s
         instance_variable_set(:"@#{model}", @elements)
         respond_to do |format|
-          format.html { haml :"#{model}/index", :locals => { :elements => @elements
} }
-          format.xml { haml :"#{model}/index", :locals => { :elements => @elements
} }
+          format.html { haml :"#{model}/index", :locals => locals}
+          format.xml  { haml :"#{model}/index", :locals => locals}
           format.json { JSON::dump({ model => @elements.map { |el| el.to_hash(self) }})
}
         end
       else
@@ -84,16 +85,18 @@ module Deltacloud::Helpers
       end
     end
 
-    def show(model)
+    def show(model, opts={})
       @benchmark = Benchmark.measure do
         @element = driver.send(model, credentials, { :id => params[:id]} )
       end
       headers['X-Backend-Runtime'] = @benchmark.real.to_s
       instance_variable_set("@#{model}", @element)
+      #checks for methods in opts:
+      locals = opts[:check] ? {model => @element, opts[:check]=>driver.respond_to?(opts[:check])}
: {model => @element}
       if @element
         respond_to do |format|
-          format.html { haml :"#{model.to_s.pluralize}/show", :locals=>{model=>@element}}
-          format.xml { haml :"#{model.to_s.pluralize}/show" , :locals=>{model=>@element}}
+          format.html { haml :"#{model.to_s.pluralize}/show", :locals=>locals}
+          format.xml { haml :"#{model.to_s.pluralize}/show" , :locals=>locals}
           format.json { JSON::dump(model => @element.to_hash(self)) }
         end
       else

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/483be9a4/server/lib/deltacloud/helpers/rabbit_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/rabbit_helper.rb b/server/lib/deltacloud/helpers/rabbit_helper.rb
index cdd0ae1..3c4d43f 100644
--- a/server/lib/deltacloud/helpers/rabbit_helper.rb
+++ b/server/lib/deltacloud/helpers/rabbit_helper.rb
@@ -18,15 +18,15 @@ Sinatra::Rabbit::Collection.class_eval do
 
   def self.standard_index_operation(opts={})
     collection_name = @collection_name
-    operation :index, :with_capability => opts[:capability] || collection_name do
-      control { filter_all collection_name }
+    operation :index, :with_capability => opts.delete(:capability) || collection_name
do
+      control { filter_all collection_name, opts }
     end
   end
 
   def self.standard_show_operation(opts={})
     collection_name = @collection_name
-    operation :show, :with_capability => opts[:capability] || collection_name do
-      control { show collection_name.to_s.singularize.intern }
+    operation :show, :with_capability => opts.delete(:capability) || collection_name do
+      control { show collection_name.to_s.singularize.intern, opts}
     end
   end
 


Mime
View raw message