Before and After Overrides

Occassionally, you may want to intercept controller calls or do some cleanup afterwards. Camping has no facility for doing this. It's not worth the bytes.

Instead, you can override service, which handles all controller calls. You can do include into specific controllers or right into the main application module.

An example would be adding sessions to your application:

 Camping.goes :YourApp

 module YourSession
     def service(*a)
         @session = YourApp::Session.new
         super(*a)
         @session.close
     end
 end

 module YourApp
     include YourSession
 end

If you need to mixin two modules with their own service methods, just tack them all on to the include call. They'll be called from left to right.

 module YourApp
     include YourSession, YourFilter
 end

For more about Camping's built-in session class, see the Camping Sessions page.


Return to CampingRulesOfThumb