Skip to content

Commit

Permalink
Updated README with more notes about 0.2 change
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwhite committed Sep 17, 2008
1 parent 7700d08 commit 6a8d4cc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
38 changes: 32 additions & 6 deletions README.rdoc
Expand Up @@ -6,7 +6,7 @@ response_for (see Ardes::ResponseFor::ClassMethods) allows you to decorate the r

As of version 0.2.0, response_for's functionality can be summed up in one sentence:

"response_for allows you to specify default responses for any action (or before filter) that doesn't render or redirect"
<b>"response_for allows you to specify default responses for any action (or before filter) that doesn't render or redirect"</b>

Actions typically do two things - interact with models, and render a response. The above simple idea allows you to decouple these
two functions (where appropriate), which means abstraction of common patterns becomes possible.
Expand All @@ -16,7 +16,6 @@ You should use 0.1-stable in your existing projects until you have runs your spe

If you want to know more about why I changed the API in 0.2 look at the bottom of this README


=== Example

class FooController < ApplicationController
Expand Down Expand Up @@ -59,13 +58,40 @@ headaches, such as:
respond_to_without_response_for in any bail out code.
* Conceptually, overriding code declared in methods, with code declared at the class level, is weird. Here's an example

class FooController < SuperclassController
response_for :index # override Superclass's index respond_to
class FooController < SuperclassController
response_for :index # override Superclass's index respond_to

def index
respond_to # one might expect this to override the above, as its declared later - but it wont!
def index
respond_to # one might expect this to override the above, as its declared later - but it wont!
end
end

So, in 0.2 a much simpler idea is behind response_for - you can declare a default response for an action which will be performed
if <b>that that action has not already performed a render or redirect</b>. This means that all of your bail out code written with
respond_to will do what it's supposed to.

==== Rewriting for 0.2

If you're upgrading, you just need to convert any actions you want to override from this:

def index
@things = Thing.all
respond_to do |format|
format.html
format.xml { render :xml => @things }
end
end

to this:

def index
@things = Thing.all
end

response_for :index fo |format|
format.html
format.xml { render :xml => @things }
end

== Previous Versions: 0.1

Expand Down
8 changes: 4 additions & 4 deletions SPECDOC
Expand Up @@ -151,20 +151,20 @@ StackingResponsesSpec::TheController with responses conditionally executed GET :
- should render :action => :foo (the default response)

StackingResponsesSpec::TheController with responses conditionally executed GET :foo, :second => true
- should execute second, then first, then in html second, response
- should execute second, then first, then html second, response
- should redirect from second response
- should NOT execute first html response

StackingResponsesSpec::TheController with responses conditionally executed GET :foo, :first => true
- should execute second, then first, then in first html response
- should execute second, then first, then first html response
- should redirect from first response
- should NOT execute second html response

StackingResponsesSpec::TheController with responses conditionally executed GET :foo, :first => true, :second => true (can't execute two html blocks)
- should execute second, then first, then in second html response
- should execute second, then first, then second html response
- should redirect from second response
- should NOT execute first html response

Finished in 0.729328 seconds
Finished in 0.494693 seconds

92 examples, 0 failures

0 comments on commit 6a8d4cc

Please sign in to comment.