require 'track_changes/filter' module TrackChanges module ClassMethods # Uses a combination of before_filter and after_filter # to act on changes made to a module during a controllers update # action. # # Parameters: # # * model: A symbol of the model instance name to track changes to # * options: An options hash the will be supplied to before_filter and after_filter. Defaults to :only => :update. # * &block: The supplied block is called with an instance of Result as its parameter. def track_changes_to(models, options = {:only => :update}, &block) append_before_filter(options) do |controller| track_filter = Filter.new(models, block) controller.track_changes_filter = track_filter track_filter.before(controller) end append_after_filter(options)do |controller| controller.track_changes_filter.after(controller) end end end end