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 2011/08/23 20:58:33 UTC

svn commit: r1160848 - in /incubator/deltacloud/trunk/server: Rakefile lib/sinatra/rabbit.rb

Author: lutter
Date: Tue Aug 23 18:58:32 2011
New Revision: 1160848

URL: http://svn.apache.org/viewvc?rev=1160848&view=rev
Log:
Added rake task to print all Rabbit routes

Signed-off-by: Michal fojtik <mf...@redhat.com>

Modified:
    incubator/deltacloud/trunk/server/Rakefile
    incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb

Modified: incubator/deltacloud/trunk/server/Rakefile
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/Rakefile?rev=1160848&r1=1160847&r2=1160848&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/Rakefile (original)
+++ incubator/deltacloud/trunk/server/Rakefile Tue Aug 23 18:58:32 2011
@@ -91,6 +91,14 @@ Gem::PackageTask.new(spec) do |pkg|
   pkg.need_tar = true
 end
 
+desc "List all REST routes defined through Rabbit"
+task :routes do
+  require 'server.rb'
+  Sinatra::Rabbit::routes.each do |m, path|
+    puts sprintf("\033[1;30m%-8s\033[0m %s", m.to_s.upcase, path)
+  end
+end
+
 namespace :mock do
   namespace :fixtures do
     desc "Setup Mock driver fixtures"

Modified: incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb?rev=1160848&r1=1160847&r2=1160848&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb (original)
+++ incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb Tue Aug 23 18:58:32 2011
@@ -23,6 +23,10 @@ module Sinatra
 
   module Rabbit
 
+    def self.routes
+      @routes ||= []
+    end
+
     class DuplicateParamException < Deltacloud::ExceptionHandler::DeltacloudException; end
     class DuplicateOperationException < Deltacloud::ExceptionHandler::DeltacloudException; end
     class DuplicateCollectionException < Deltacloud::ExceptionHandler::DeltacloudException; end
@@ -84,6 +88,7 @@ module Sinatra
 
       def generate_documentation
         coll, oper = @collection, self
+        Rabbit::routes << [:get, "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/docs/#{@collection.name}/#{@name}"]
         ::Sinatra::Application.get("#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/docs/#{@collection.name}/#{@name}") do
           @collection, @operation = coll, oper
           @features = driver.features_for_operation(coll.name, oper.name)
@@ -96,6 +101,7 @@ module Sinatra
 
       def generate_options
         current_operation = self
+        Rabbit::routes << [:options, "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/#{current_operation.collection.name}/#{current_operation.name}"]
         ::Sinatra::Application.options("#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/#{current_operation.collection.name}/#{current_operation.name}") do
           required_params = current_operation.effective_params(driver).collect do |name, validation|
             name.to_s if validation.type.eql?(:required)
@@ -136,6 +142,7 @@ module Sinatra
       end
 
       def generate
+        Rabbit::routes << [@method, "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/#{path}"]
         ::Sinatra::Application.send(@method, "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/#{path}", {}, &@control)
         # Set up some Rails-like URL helpers
         if name == :index
@@ -218,6 +225,7 @@ module Sinatra
 
       def generate_head
         current_collection = self
+        Rabbit::routes << [:head, "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/#{name}"]
         ::Sinatra::Application.head("#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/#{name}") do
           methods_allowed = current_collection.operations.collect { |o| o[1].method.to_s.upcase }.uniq.join(',')
           headers 'Allow' => "HEAD,OPTIONS,#{methods_allowed}"
@@ -227,6 +235,7 @@ module Sinatra
 
       def generate_options
         current_collection = self
+        Rabbit::routes << [:options, "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/#{name}"]
         ::Sinatra::Application.options("#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/#{name}") do
           operations_allowed = current_collection.operations.collect { |o| o[0] }.join(',')
           headers 'X-Operations-Allowed' => operations_allowed
@@ -236,6 +245,7 @@ module Sinatra
 
       def generate_documentation
         coll = self
+        Rabbit::routes << [:get, "#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/docs/#{@name}"]
         ::Sinatra::Application.get("#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/docs/#{@name}") do
           coll.check_supported(driver)
           @collection = coll