deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tong Li <>
Subject DeltaCloud questions
Date Tue, 09 Aug 2011 20:32:40 GMT

I am trying to figure out how DC works and I kept looking at the code in
rabbit.rb and server.rb. I had hard time in the last couple of days
figuring out what the following code does and how it does it. Please shed
some lights. thanks.

here are the code that I could not get a handle of.

    control do
      driver.destroy_storage_snapshot(credentials, params)
      respond_to do |format|
        format.xml { return 204 }
        format.json { return 204 }
        format.html { return redirect(storage_snapshots_url) }

 def respond_to(&block)
       wants = {}

        def wants.method_missing(type, *args, &handler)
          self[type] = handler

        # Set proper content-type and encoding for
        # text based formats
        puts format.inspect
        if [:xml, :gv, :html, :json].include?(format)
          content_type format, :charset => 'utf-8'
        yield wants
        # Raise this error if requested format is not defined
        # in respond_to { } block.
        raise MissingTemplate if wants[format].nil?


control block gets called when a request is received, then it calls
respond_to method. respond_to method sets the variable "wants" to be an
empty hash first, then yield to the code

        format.xml { return 204 }
        format.json { return 204 }
        format.html { return redirect(storage_snapshots_url) }

What puzzled me is how that hash gets member of xml, json and html, and
where and how each member was set up as a proc or method?

I've also wrote a piece of code which tries to add a new URL
like /api/john, here is my test code.

collection :john do
  description <<EOS
whatever this is just a test

  operation :index do
    description "list whatever"
    control do
      puts "came here anyway"
      response.status = 200  # OK

However, the code does not seem get executed when request
(http://localhost:3001/api/john) was received. The browser will always
return 404 error, it seems to me that I am missing some of the fundamentals
of rabbit, please point out what I did wrong or missed.

Thanks a lot.
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message