# The Userstamp module, when included into a controller, adds a before filter
# (named set_stamper) and an after filter (name reset_stamper).
# These methods assume a couple of things, but can be re-implemented in your
# controller to better suite your application.
#
# See the documentation for set_stamper and reset_stamper for
# specific implementation details.
module ActiveRecord::Userstamp::ControllerAdditions
def self.included(base) # :nodoc:
base.send :include, InstanceMethods
base.before_filter :set_stamper
base.after_filter :reset_stamper
end
module InstanceMethods
private
# The set_stamper method as implemented here assumes a couple
# of things. First, that you are using a +User+ model as the stamper
# and second that your controller has a current_user method
# that contains the currently logged in stamper. If either of these
# are not the case in your application you will want to manually add
# your own implementation of this method to the private section of
# the controller where you are including the Userstamp module.
def set_stamper
User.stamper = self.current_user
end
# The reset_stamper method as implemented here assumes that a
# +User+ model is being used as the stamper. If this is not the case then
# you will need to manually add your own implementation of this method to
# the private section of the controller where you are including the
# Userstamp module.
def reset_stamper
User.reset_stamper
end
end
end
if defined?(ActionController)
ActionController::Base.send(:include, ActiveRecord::Userstamp::ControllerAdditions)
end