public
Description: response for lets you decorate your actions respond_to blocks
Homepage: http://blog.ardes.com/response_for
Clone URL: git://github.com/ianwhite/response_for.git
Click here to lend your support to: response_for and make a donation at www.pledgie.com !
Removed uneccessary @respond_to_performed, and chain of respond_to, which means 
that erase_render_results will just work without any tinkering
ianwhite (author)
Sun Oct 19 22:49:32 -0700 2008
commit  94749ff29a5b6103f1097aa97ab7a30ff4a69d8e
tree    55e5d0208227f9a442a21693d67850ad46171a07
parent  4d9e74e45897d221d72e547c903c20d22cdbca19
...
6
7
8
9
10
11
12
...
119
120
121
122
123
124
 
 
 
 
 
 
 
 
 
125
126
127
128
129
130
 
131
132
133
 
134
135
136
137
138
 
139
140
 
141
142
143
...
149
150
151
152
153
154
155
156
157
158
159
...
6
7
8
 
9
10
11
...
118
119
120
 
 
 
121
122
123
124
125
126
127
128
129
130
131
132
133
134
 
135
136
137
 
138
139
140
141
142
 
143
144
 
145
146
147
148
...
154
155
156
 
 
 
 
 
157
158
159
0
@@ -6,7 +6,6 @@ module Ardes #:nodoc:
0
         extend ClassMethods
0
         alias_method_chain :default_render, :response_for
0
         alias_method_chain :template_exists?, :response_for
0
-        alias_method_chain :respond_to, :response_for
0
       end
0
     end
0
     
0
@@ -119,25 +118,31 @@ module Ardes #:nodoc:
0
     end
0
     
0
   protected
0
-    # does a response exist for the current action?
0
-    def response_exists?
0
-      self.class.action_responses.keys.include?(action_name.to_s)
0
+    # return the responses defined by response_for for the current action
0
+    def action_responses
0
+      self.class.action_responses[action_name] || []
0
+    end
0
+    
0
+    # respond_to sets the content type on the response, so we use that to tell
0
+    # if respond_to has been performed
0
+    def respond_to_performed?
0
+      (response && response.content_type) ? true : false
0
     end
0
     
0
     # we extend template_exists? to return true if a template OR a response exists corresponding to the current action.
0
     # This is so that a default render will be triggered when no action, but a repsonse does exist.
0
     def template_exists_with_response_for?
0
-      response_exists? || template_exists_without_response_for?
0
+      action_responses.any? || template_exists_without_response_for?
0
     end
0
 
0
-    # if there are responses for the current action, then respond_to them
0
+    # if the response.content_type has not been set (if it has, then responthere are responses for the current action, then respond_to them
0
     #
0
     # we rescue the case where there were no responses, so that the default_render
0
     # action will be performed
0
     def respond_to_action_responses
0
-      if !@respond_to_performed && (responses = self.class.action_responses[action_name]) && responses.any?
0
+      if !respond_to_performed? && action_responses.any?
0
         respond_to do |responder|
0
-          responses.each {|response| instance_exec(responder, &response) }
0
+          action_responses.each {|response| instance_exec(responder, &response) }
0
         end rescue Responder::NoResponsesError
0
       end
0
     end
0
@@ -149,11 +154,6 @@ module Ardes #:nodoc:
0
       default_render_without_response_for unless performed?
0
     end
0
     
0
-    def respond_to_with_response_for(*args, &block)
0
-      @respond_to_performed = true
0
-      respond_to_without_response_for(*args, &block)
0
-    end
0
-    
0
     # included into ActionController::MimeResponds::Responder
0
     module Responder
0
       class NoResponsesError < RuntimeError; end

Comments