Just to chime in, this is related-but-not-quite,

I've been working off and on on a little library for Rails-style
RESTful controllers. It's called "Sleeping Bag":
http://code.google.com/p/sleepingbag

It's not quite ready yet, so don't expect it to work well, but I
thought maybe someone would find it interesting. It basically just
maps HTTP actions and the stuff in the path to methods on your
controllers. You could have a controller like this:

  class Planes < R '/planes', '/planes/([^\/]+)', '/planes/([^\/]+)/([^\/]+)'
    include SleepingBag

    def index
      @planes = Plane.find(:all)
      render :planes_index
    end

    def show(id)
      @plane = Plane.find(id)
      render :show_plane
    end
  end

"GET /planes" and "GET /planes/747" are mapped to the index and show
methods, respectively, based on the methods' arity and the fact that
index and show are defined by default to be "standard actions", those
represented by just an HTTP method, not an aspect. (I'm doing aspects
without semicolons, like Rails now is.)

Aspects and other standard methods are defined by defining methods,
mapped to GET by default. So, to continue with the Planes
controller...

  def wingspan(id)
    @plane = Plane.find(id)
    render :plane_wingspan
  end

This would map to "GET /planes/747/wingspan". To fly a plane:

  methods[:fly] = [:post]
  def fly(id)
    @plane = Plane.find(id)
    @plane.fly!
    "Bon voyage!"
  end

This means that only "POST /planes/747/fly" will call the fly action.

I want to make declaration of controllers simpler, like this:

  class Planes < ZZZ
    def index
      # ...
    end

    # ...
  end

Coming soon, possibly...


-- Michael Daines
_______________________________________________
Camping-list mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/camping-list

Reply via email to