lib/stampable.rb
def stampable(options = {})
          compatability = Ddb::Userstamp.compatibility_mode
          defaults  = {
            :stamper_class_name => :user,
            :creator_attribute  => (compatability ? :created_by : :creator_id),
            :updater_attribute  => (compatability ? :updated_by : :updater_id),
            :deleter_attribute  => (compatability ? :deleted_by : :deleter_id),
            :deleter            => options.has_key?(:deleter_attribute),
            :with_deleted       => false
          }.merge(options)

          self.stamper_class_name = defaults[:stamper_class_name].to_sym
          self.creator_attribute  = defaults[:creator_attribute].to_sym
          self.updater_attribute  = defaults[:updater_attribute].to_sym
          self.deleter_attribute  = defaults[:deleter_attribute].to_sym

          class_eval do
            klass = "::#{stamper_class_name.to_s.singularize.camelize}"

            if defaults[:with_deleted]
              belongs_to :creator, :class_name => klass, :foreign_key => creator_attribute, :with_deleted => true
              belongs_to :updater, :class_name => klass, :foreign_key => updater_attribute, :with_deleted => true
            else
              belongs_to :creator, :class_name => klass, :foreign_key => creator_attribute
              belongs_to :updater, :class_name => klass, :foreign_key => updater_attribute
            end

            before_validation :set_updater_attribute
            before_validation :set_creator_attribute, :on => :create

            if defaults[:deleter]
              if defaults[:with_deleted]
                belongs_to :deleter, :class_name => klass, :foreign_key => deleter_attribute, :with_deleted => true
              else
                belongs_to :deleter, :class_name => klass, :foreign_key => deleter_attribute
              end

              before_destroy :set_deleter_attribute

            end
          end
        end
# This method is automatically called on for all classes that inherit from
# ActiveRecord, but if you need to customize how the plug-in functions, this is the
# method to use. Here's an example:
#
#   class Post < ActiveRecord::Base
#     stampable :stamper_class_name => :person,
#               :creator_attribute  => :create_user,
#               :updater_attribute  => :update_user,
#               :deleter_attribute  => :delete_user,
#               :deleter            => true,
#               :with_deleted       => true
#   end
#
# The method will automatically setup all the associations,
# and create <tt>before_validation</tt> & <tt>before_destroy</tt> callbacks for doing the stamping.
#
# By default, the deleter association and before filter are not defined unless
# you set the :deleter_attribute or set the :deleter option to true.
#
# When using the new acts_as_paranoid gem (https://github.com/goncalossilva/rails3_acts_as_paranoid)
# the :with_deleted option can be used to setup the associations to return objects that have been soft deleted.
#
This method is automatically called on for all classes that inherit from
ActiveRecord, but if you need to customize how the plug-in functions, this is the
method to use. Here's an example.



The method will automatically setup all the associations,
and create before_validation & before_destroy callbacks for doing the stamping.

By default, the deleter association and before filter are not defined unless
you set the :deleter_attribute or set the :deleter option to true.

When using the new acts_as_paranoid gem
the :with_deleted option can be used to setup the associations to return objects that have been soft deleted.
This method is automatically called on for all classes that inherit from ActiveRecord but if you need to customize how the plug - in functions this is the method to use . Here ' s an example . The method will automatically setup all the associations and create before_validation & before_destroy callbacks for doing the stamping . By default the deleter association and before filter are not defined unless you set the : deleter_attribute or set the : deleter option to true . When using the new acts_as_paranoid gem the : with_deleted option can be used to setup the associations to return objects that have been soft deleted .
def stampable(options = {})
          compatability = Ddb::Userstamp.compatibility_mode
          defaults  = {
            :stamper_class_name => :user,
            :creator_attribute  => (compatability ? :created_by : :creator_id),
            :updater_attribute  => (compatability ? :updated_by : :updater_id),
            :deleter_attribute  => (compatability ? :deleted_by : :deleter_id),
            :deleter            => options.has_key?(:deleter_attribute),
            :with_deleted       => false
          }.merge(options)
          self.stamper_class_name = defaults[:stamper_class_name].to_sym
          self.creator_attribute  = defaults[:creator_attribute].to_sym
          self.updater_attribute  = defaults[:updater_attribute].to_sym
          self.deleter_attribute  = defaults[:deleter_attribute].to_sym
          class_eval do
            klass = "::#{stamper_class_name.to_s.singularize.camelize}"
            if defaults[:with_deleted]
              belongs_to :creator, :class_name => klass, :foreign_key => creator_attribute, :with_deleted => true
              belongs_to :updater, :class_name => klass, :foreign_key => updater_attribute, :with_deleted => true
            else
              belongs_to :creator, :class_name => klass, :foreign_key => creator_attribute
              belongs_to :updater, :class_name => klass, :foreign_key => updater_attribute
            end
            before_validation :set_updater_attribute
            before_validation :set_creator_attribute, :on => :create
            if defaults[:deleter]
              if defaults[:with_deleted]
                belongs_to :deleter, :class_name => klass, :foreign_key => deleter_attribute, :with_deleted => true
              else
                belongs_to :deleter, :class_name => klass, :foreign_key => deleter_attribute
              end
              before_destroy :set_deleter_attribute
            end
          end
        end
def stampable ( options = { } ) compatability = Ddb :: Userstamp . compatibility_mode defaults = { :stamper_class_name => :user , :creator_attribute => ( compatability ? :created_by : :creator_id ) , :updater_attribute => ( compatability ? :updated_by : :updater_id ) , :deleter_attribute => ( compatability ? :deleted_by : :deleter_id ) , :deleter => options . has_key? ( :deleter_attribute ) , :with_deleted => false } . merge ( options ) self . stamper_class_name = defaults [ :stamper_class_name ] . to_sym self . creator_attribute = defaults [ :creator_attribute ] . to_sym self . updater_attribute = defaults [ :updater_attribute ] . to_sym self . deleter_attribute = defaults [ :deleter_attribute ] . to_sym class_eval do klass = "::#{stamper_class_name.to_s.singularize.camelize}" if defaults [ :with_deleted ] belongs_to :creator , :class_name => klass , :foreign_key => creator_attribute , :with_deleted => true belongs_to :updater , :class_name => klass , :foreign_key => updater_attribute , :with_deleted => true else belongs_to :creator , :class_name => klass , :foreign_key => creator_attribute belongs_to :updater , :class_name => klass , :foreign_key => updater_attribute end before_validation :set_updater_attribute before_validation :set_creator_attribute , :on => :create if defaults [ :deleter ] if defaults [ :with_deleted ] belongs_to :deleter , :class_name => klass , :foreign_key => deleter_attribute , :with_deleted => true else belongs_to :deleter , :class_name => klass , :foreign_key => deleter_attribute end before_destroy :set_deleter_attribute end end end
This method is automatically called on for all classes that inherit from
ActiveRecord, but if you need to customize how the plug-in functions, this is the
method to use.
This method is automatically called on for all classes that inherit from ActiveRecord but if you need to customize how the plug - in functions this is the method to use .
options