Skip to content

Commit

Permalink
Revert "Addition of automatic_mode option and change to setting of cr…
Browse files Browse the repository at this point in the history
…eator attribute"

This reverts commit 9cc7c9e.
  • Loading branch information
Chris Hilton committed Jan 25, 2013
1 parent 9cc7c9e commit af0f175
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
7 changes: 1 addition & 6 deletions Readme.rdoc
Expand Up @@ -20,11 +20,6 @@ results in associations defined like so:

belongs_to :creator, :class_name => "::User", :foreign_key => :created_by, :with_deleted => true

This fork also includes the addition of the automatic_mode option which controls whether whether classes that inherit from ActiveRecord are made stampable automatically. To turn automatic mode off, place the following line in your environment.rb

Ddb::Userstamp.automatic_mode = false

This fork also includes a change so that the creator attribute is only set if its value is blank allowing for a manual override.

== Using the Fork

Expand All @@ -35,7 +30,7 @@ To use this fork add the following to your application gemfile:

== Overview

Userstamp extends ActiveRecord::Base[http://api.rubyonrails.com/classes/ActiveRecord/Base.html] to add automatic or selective updating of 'creator',
Userstamp extends ActiveRecord::Base[http://api.rubyonrails.com/classes/ActiveRecord/Base.html] to add automatic updating of 'creator',
'updater', and 'deleter' attributes. It is based loosely on the ActiveRecord::Timestamp[http://api.rubyonrails.com/classes/ActiveRecord/Timestamp.html] module.

Two class methods (<tt>model_stamper</tt> and <tt>stampable</tt>) are implemented in this plugin.
Expand Down
22 changes: 3 additions & 19 deletions lib/stampable.rb
Expand Up @@ -14,19 +14,6 @@ module Userstamp
mattr_accessor :compatibility_mode
@@compatibility_mode = false

# Determines whether classes that inherit from ActiveRecord
# are made stampable automatically (default)
# or selectively in which case the method must be called within each
# model that needs to be stamped.
#
# To turn automatic mode off, place the following line in your environment.rb
# file:
#
# Ddb::Userstamp.automatic_mode = false
#
mattr_accessor :automatic_mode
@@automatic_mode = true

# Extends the stamping functionality of ActiveRecord by automatically recording the model
# responsible for creating, updating, and deleting the current object. See the Stamper
# and Userstamp modules for further documentation on how the entire process works.
Expand Down Expand Up @@ -60,14 +47,13 @@ def self.included(base) #:nodoc:
# Defaults to :deleted_by when compatibility mode is on
class_attribute :deleter_attribute

self.stampable if Ddb::Userstamp.automatic_mode == true
self.stampable
end
end

module ClassMethods
# This method is automatically called on for all classes that inherit from
# ActiveRecord when using the default automatic mode
# but if you need to customize how the plug-in functions, this is the
# 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
Expand Down Expand Up @@ -160,9 +146,7 @@ def has_stamper?
def set_creator_attribute
return unless self.record_userstamp
if respond_to?(self.creator_attribute.to_sym) && has_stamper?
if self.send(self.creator_attribute.to_sym).blank?
self.send("#{self.creator_attribute}=".to_sym, self.class.stamper_class.stamper)
end
self.send("#{self.creator_attribute}=".to_sym, self.class.stamper_class.stamper)
end
end

Expand Down

0 comments on commit af0f175

Please sign in to comment.