You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A side effect of the fix for issue 1 is that blocks that use return generate a LocalJumpError now. Since predicates are conceptually like lambdas, it's much more flexible to support return within predicate blocks -- especially when transplanting business logic from legacy sources that may be hard to refactor into a non-return format.
For example:
# in a controller action...
predicate(:show_secret?) {
if my_terrible_secret
return true
else
return false
end
}
# then, when used in the view...
Started GET "/main/index" for 127.0.0.1 at 2012-06-14 18:13:07 -0400
Connecting to database specified by database.yml
Processing by MainController#index as HTML
Rendered main/index.html.erb within layouts/application (9.0ms)
Completed 500 Internal Server Error in 74ms
ActionView::Template::Error (unexpected return):
1: <h1>Main#index</h1>
2: <p>Find me in app/views/main/index.html.erb</p>
3: <% if show_secret? %>
4: <p>THIS IS THE SECRET BLOCK</p>
5: <% end %>
app/controllers/main_controller.rb:8:in `block in index'
app/views/main/index.html.erb:3:in `_app_views_main_index_html_erb___2806522044999392377_25110420'
Rendered /local/rvm/gems/ruby-1.9.3-p194@conditest/gems/actionpack-3.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.erb (19.2ms)
Rendered /local/rvm/gems/ruby-1.9.3-p194@conditest/gems/actionpack-3.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.9ms)
Rendered /local/rvm/gems/ruby-1.9.3-p194@conditest/gems/actionpack-3.2.6/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (30.5ms)
[2012-06-14 18:13:08] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
The text was updated successfully, but these errors were encountered:
This fix was a little harder to get right. It turns out that define_method(name,&block) has special magic that keeps block as a method/lambda if it is so inclined, while define_method(name) {} always creates a new Proc. (This is why condi-0.0.6 worked and 0.0.7 didn't.) So I had to switch strategies and define an impl the old way, while wrapping it the new way with the request id check logic. Phew!
Anyway, cooking with gas now:
Started GET "/main/index" for 127.0.0.1 at 2012-06-14 19:46:02 -0400
Connecting to database specified by database.yml
Processing by MainController#index as HTML
Rendered main/index.html.erb within layouts/application (2.9ms)
Completed 200 OK in 164ms (Views: 160.8ms | ActiveRecord: 0.0ms)
A side effect of the fix for issue 1 is that blocks that use
return
generate a LocalJumpError now. Since predicates are conceptually like lambdas, it's much more flexible to supportreturn
within predicate blocks -- especially when transplanting business logic from legacy sources that may be hard to refactor into a non-return format.For example:
The text was updated successfully, but these errors were encountered: