This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: What's in Camping 1.4?
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Adding stuff like sessioning and authentication demands hooks on the controller. Rails uses hooks like before_filter to do this. Camping doesn’t have bytes to spare to make this happen, but things have been re-stacked to let you slide in new service methods which intercept all controller calls.
class LoginError < Exception; end
module ClownsOnly
def service(*a)
unless @state.occupation == :clown
raise LoginError, "For clown's eyes only."
end
super(*a)
end
end
This service method can be slid into your application’s top module like so:
Camping.goes :Blog
module Blog
include ClownsOnly
end