userstamp 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/Gemfile +9 -0
  2. data/Gemfile.lock +35 -0
  3. data/Rakefile +2 -2
  4. data/{README → Readme.rdoc} +27 -35
  5. data/VERSION +1 -1
  6. data/lib/stampable.rb +18 -15
  7. data/lib/userstamp.rb +4 -0
  8. data/rdoc/classes/Ddb/Userstamp.html +4 -4
  9. data/rdoc/classes/Ddb/Userstamp/Stampable/ClassMethods.html +41 -38
  10. data/rdoc/classes/Ddb/Userstamp/Stamper/InstanceMethods.html +1 -1
  11. data/rdoc/classes/Userstamp.html +118 -0
  12. data/rdoc/created.rid +1 -1
  13. data/rdoc/files/CHANGELOG.html +1 -1
  14. data/rdoc/files/LICENSE.html +1 -1
  15. data/rdoc/files/{README.html → Readme_rdoc.html} +62 -61
  16. data/rdoc/files/lib/migration_helper_rb.html +1 -1
  17. data/rdoc/files/lib/stampable_rb.html +1 -1
  18. data/rdoc/files/lib/stamper_rb.html +1 -1
  19. data/rdoc/files/lib/userstamp_rb.html +10 -1
  20. data/rdoc/fr_class_index.html +1 -0
  21. data/rdoc/fr_file_index.html +1 -1
  22. data/rdoc/index.html +1 -1
  23. data/test/compatibility_stamping_test.rb +29 -23
  24. data/test/helper.rb +61 -0
  25. data/test/models/comment.rb +1 -0
  26. data/test/models/foo.rb +3 -0
  27. data/test/models/post.rb +10 -1
  28. data/test/schema.rb +6 -8
  29. data/test/stamping_test.rb +45 -17
  30. data/test/userstamp_controller_test.rb +24 -39
  31. data/test/userstamp_test.rb +7 -0
  32. data/userstamp.gemspec +21 -24
  33. metadata +28 -24
  34. data/test/database.yml +0 -4
  35. data/test/fixtures/comments.yml +0 -16
  36. data/test/fixtures/people.yml +0 -11
  37. data/test/fixtures/posts.yml +0 -9
  38. data/test/fixtures/users.yml +0 -7
  39. data/test/helpers/functional_test_helper.rb +0 -37
  40. data/test/helpers/unit_test_helper.rb +0 -29
  41. data/test/models/ping.rb +0 -7
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'redgreen'
5
+ gem 'jeweler'
6
+ gem 'activerecord', :require => 'active_record'
7
+ gem 'activesupport', :require => 'active_support'
8
+ gem 'actionpack', :require => 'action_pack'
9
+ gem 'sqlite3-ruby', :require => 'sqlite3'
@@ -0,0 +1,35 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionpack (2.3.8)
5
+ activesupport (= 2.3.8)
6
+ rack (~> 1.1.0)
7
+ activerecord (2.3.8)
8
+ activesupport (= 2.3.8)
9
+ activesupport (2.3.8)
10
+ gemcutter (0.5.0)
11
+ json_pure
12
+ git (1.2.5)
13
+ jeweler (1.4.0)
14
+ gemcutter (>= 0.1.0)
15
+ git (>= 1.2.5)
16
+ rubyforge (>= 2.0.0)
17
+ json_pure (1.4.3)
18
+ rack (1.1.0)
19
+ rake (0.8.7)
20
+ redgreen (1.2.2)
21
+ rubyforge (2.0.4)
22
+ json_pure (>= 1.1.7)
23
+ sqlite3-ruby (1.2.5)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ actionpack
30
+ activerecord
31
+ activesupport
32
+ jeweler
33
+ rake
34
+ redgreen
35
+ sqlite3-ruby
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
17
17
  rdoc.rdoc_dir = 'rdoc'
18
18
  rdoc.title = 'Userstamp'
19
19
  rdoc.options << '--line-numbers' << '--inline-source'
20
- rdoc.rdoc_files.include('README', 'CHANGELOG', 'LICENSE')
20
+ rdoc.rdoc_files.include('Readme.rdoc', 'CHANGELOG', 'LICENSE')
21
21
  rdoc.rdoc_files.include('lib/**/*.rb')
22
22
  end
23
23
 
@@ -34,5 +34,5 @@ begin
34
34
 
35
35
  Jeweler::GemcutterTasks.new
36
36
  rescue LoadError
37
- puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
37
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
38
38
  end
@@ -1,8 +1,8 @@
1
- = Userstamp Plugin (v 2.0)
1
+ Userstamp
2
2
 
3
3
  == Overview
4
4
 
5
- The Userstamp Plugin extends ActiveRecord::Base[http://api.rubyonrails.com/classes/ActiveRecord/Base.html] to add automatic updating of 'creator',
5
+ Userstamp extends ActiveRecord::Base[http://api.rubyonrails.com/classes/ActiveRecord/Base.html] to add automatic updating of 'creator',
6
6
  'updater', and 'deleter' attributes. It is based loosely on the ActiveRecord::Timestamp[http://api.rubyonrails.com/classes/ActiveRecord/Timestamp.html] module.
7
7
 
8
8
  Two class methods (<tt>model_stamper</tt> and <tt>stampable</tt>) are implemented in this plugin.
@@ -13,62 +13,53 @@ created, updated, or deleted by 'stampers'.
13
13
 
14
14
  == Installation
15
15
  - As Rails plugin: `script/plugin install git://github.com/delynn/userstamp.git `
16
- - As gem: ` sudo gem install userstamp -s http://gemcutter.org `
17
-
18
- Once installed you will need to restart your application for the plugin to be loaded into the Rails
19
- environment.
20
-
21
- You might also be interested in using Piston[http://piston.rubyforge.org/index.html] to manage the
22
- importing and future updating of this plugin.
16
+ - As gem: ` sudo gem install userstamp `
23
17
 
24
18
  == Usage
25
- In this new version of the Userstamp plug-in, the assumption is that you have two different
26
- categories of objects; those that mani˝pulate, and those that are manipulated. For those objects
19
+ The assumption is that you have two different
20
+ categories of objects; those that manipulate, and those that are manipulated. For those objects
27
21
  that are being manipulated there's the Stampable module and for the manipulators there's the
28
22
  Stamper module. There's also the actual Userstamp module for your controllers that assists in
29
23
  setting up your environment on a per request basis.
30
24
 
31
- To better understand how all this works, I think an example is in order. For this example we will
32
- assume that a weblog application is comprised of User and Post objects. The first thing we need to
33
- do is create the migrations for these objects, and the plug-in gives you a <tt>userstamps</tt>
34
- method for very easily doing this:
25
+ === Example
26
+ Assume a weblog application has User and Post objects.
27
+ 1. Create the migrations for these objects
35
28
 
36
29
  class CreateUsers < ActiveRecord::Migration
37
30
  def self.up
38
31
  create_table :users, :force => true do |t|
39
- t.timestamps
40
- t.userstamps
41
- t.name
32
+ ...
33
+ t.userstamps # use t.userstamps(true) if you also want 'deleter_id'
42
34
  end
43
35
  end
44
-
36
+
45
37
  def self.down
46
38
  drop_table :users
47
39
  end
48
40
  end
49
-
41
+
50
42
  class CreatePosts < ActiveRecord::Migration
51
43
  def self.up
52
44
  create_table :posts, :force => true do |t|
53
- t.timestamps
54
- t.userstamps
55
- t.title
45
+ ...
46
+ t.userstamps # use t.userstamps(true) if you also want 'deleter_id'
56
47
  end
57
48
  end
58
-
49
+
59
50
  def self.down
60
51
  drop_table :posts
61
52
  end
62
53
  end
63
54
 
64
- Second, since Users are going to manipulate other objects in our project, we'll use the
65
- <tt>model_stamper</tt> method in our User class:
55
+ 2. Users are going to manipulate Post's, use the
56
+ <tt>model_stamper</tt>:
66
57
 
67
58
  class User < ActiveRecord::Base
68
59
  model_stamper
69
60
  end
70
61
 
71
- Finally, we need to setup a controller to set the current user of the application. It's
62
+ 3. Setup a controller to set the current user of the application. It's
72
63
  recommended that you do this in your ApplicationController:
73
64
 
74
65
  class ApplicationController < ActionController::Base
@@ -106,9 +97,6 @@ User class. They are #stamper= and #stamper and look like this:
106
97
  Thread.current["#{self.to_s.downcase}_#{self.object_id}_stamper"]
107
98
  end
108
99
 
109
- The big change with this new version is that we are now using Thread.current to save the current
110
- stamper so as to avoid conflict with concurrent requests.
111
-
112
100
  The <tt>stampable</tt> method allows you to customize what columns will get stamped, and also
113
101
  creates the +creator+, +updater+, and +deleter+ associations.
114
102
 
@@ -131,10 +119,10 @@ If you need to customize the columns that are stamped, the <tt>stampable</tt> me
131
119
  completely customized. Here's an quick example:
132
120
 
133
121
  class Post < ActiveRecord::Base
134
- acts_as_stampable :stamper_class_name => :person,
135
- :creator_attribute => :create_user,
136
- :updater_attribute => :update_user,
137
- :deleter_attribute => :delete_user
122
+ stampable :stamper_class_name => :person,
123
+ :creator_attribute => :create_user,
124
+ :updater_attribute => :update_user,
125
+ :deleter_attribute => :delete_user
138
126
  end
139
127
 
140
128
  If you are upgrading your application from the old version of Userstamp, there is a compatibility
@@ -174,4 +162,8 @@ to merge any changes from other people's branches that would be beneficial to th
174
162
 
175
163
  == Credits and Special Thanks
176
164
  The original idea for this plugin came from the Rails Wiki article entitled
177
- {Extending ActiveRecord}[http://wiki.rubyonrails.com/rails/pages/ExtendingActiveRecordExample].
165
+ {Extending ActiveRecord}[http://wiki.rubyonrails.com/rails/pages/ExtendingActiveRecordExample].
166
+
167
+ == Contributors / maintenance / enhancement
168
+ - {Michael Grosser}[http://pragmatig.com]
169
+ - {John Dell}[http://blog.spovich.com/]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.0.1
@@ -61,17 +61,22 @@ module Ddb #:nodoc:
61
61
  # :creator_attribute => :create_user,
62
62
  # :updater_attribute => :update_user,
63
63
  # :deleter_attribute => :delete_user
64
+ # :deleter => true
64
65
  # end
65
66
  #
66
67
  # The method will automatically setup all the associations, and create <tt>before_save</tt>
67
68
  # and <tt>before_create</tt> filters for doing the stamping.
69
+ # By default, the deleter association and before filter are not defined unless you are using
70
+ # acts_as_paranoid or you set the :deleter_attribute or set the :deleter option to true.
68
71
  def stampable(options = {})
72
+ compatability = Ddb::Userstamp.compatibility_mode
69
73
  defaults = {
70
- :stamper_class_name => :user,
71
- :creator_attribute => Ddb::Userstamp.compatibility_mode ? :created_by : :creator_id,
72
- :updater_attribute => Ddb::Userstamp.compatibility_mode ? :updated_by : :updater_id,
73
- :deleter_attribute => Ddb::Userstamp.compatibility_mode ? :deleted_by : :deleter_id
74
- }.merge(options)
74
+ :stamper_class_name => :user,
75
+ :creator_attribute => (compatability ? :created_by : :creator_id),
76
+ :updater_attribute => (compatability ? :updated_by : :updater_id),
77
+ :deleter_attribute => (compatability ? :deleted_by : :deleter_id),
78
+ :deleter => !!(options.has_key?(:deleter_attribute) or defined?(Caboose::Acts::Paranoid))
79
+ }.merge(options)
75
80
 
76
81
  self.stamper_class_name = defaults[:stamper_class_name].to_sym
77
82
  self.creator_attribute = defaults[:creator_attribute].to_sym
@@ -79,18 +84,15 @@ module Ddb #:nodoc:
79
84
  self.deleter_attribute = defaults[:deleter_attribute].to_sym
80
85
 
81
86
  class_eval do
82
- belongs_to :creator, :class_name => self.stamper_class_name.to_s.singularize.camelize,
83
- :foreign_key => self.creator_attribute
84
-
85
- belongs_to :updater, :class_name => self.stamper_class_name.to_s.singularize.camelize,
86
- :foreign_key => self.updater_attribute
87
-
87
+ klass = stamper_class_name.to_s.singularize.camelize
88
+ belongs_to :creator, :class_name => klass, :foreign_key => creator_attribute
89
+ belongs_to :updater, :class_name => klass, :foreign_key => updater_attribute
90
+
88
91
  before_save :set_updater_attribute
89
92
  before_create :set_creator_attribute
90
-
91
- if defined?(Caboose::Acts::Paranoid)
92
- belongs_to :deleter, :class_name => self.stamper_class_name.to_s.singularize.camelize,
93
- :foreign_key => self.deleter_attribute
93
+
94
+ if defaults[:deleter]
95
+ belongs_to :deleter, :class_name => klass, :foreign_key => deleter_attribute
94
96
  before_destroy :set_deleter_attribute
95
97
  end
96
98
  end
@@ -107,6 +109,7 @@ module Ddb #:nodoc:
107
109
  original_value = self.record_userstamp
108
110
  self.record_userstamp = false
109
111
  yield
112
+ ensure
110
113
  self.record_userstamp = original_value
111
114
  end
112
115
 
@@ -2,6 +2,10 @@ require 'stamper'
2
2
  require 'stampable'
3
3
  require 'migration_helper'
4
4
 
5
+ module Userstamp
6
+ VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
7
+ end
8
+
5
9
  module Ddb
6
10
  module Controller
7
11
  # The Userstamp module, when included into a controller, adds a before filter
@@ -55,6 +55,10 @@
55
55
  <tr class="top-aligned-row">
56
56
  <td><strong>In:</strong></td>
57
57
  <td>
58
+ <a href="../../files/lib/stamper_rb.html">
59
+ lib/stamper.rb
60
+ </a>
61
+ <br />
58
62
  <a href="../../files/lib/migration_helper_rb.html">
59
63
  lib/migration_helper.rb
60
64
  </a>
@@ -62,10 +66,6 @@
62
66
  <a href="../../files/lib/stampable_rb.html">
63
67
  lib/stampable.rb
64
68
  </a>
65
- <br />
66
- <a href="../../files/lib/stamper_rb.html">
67
- lib/stamper.rb
68
- </a>
69
69
  <br />
70
70
  </td>
71
71
  </tr>
@@ -124,48 +124,50 @@ is the method to use. Here&#8216;s an example:
124
124
  :creator_attribute =&gt; :create_user,
125
125
  :updater_attribute =&gt; :update_user,
126
126
  :deleter_attribute =&gt; :delete_user
127
+ :deleter =&gt; true
127
128
  end
128
129
  </pre>
129
130
  <p>
130
131
  The method will automatically setup all the associations, and create
131
132
  <tt>before_save</tt> and <tt>before_create</tt> filters for doing the
132
- stamping.
133
+ stamping. By default, the deleter association and before filter are not
134
+ defined unless you are using acts_as_paranoid or you set the
135
+ :deleter_attribute or set the :deleter option to true.
133
136
  </p>
134
137
  <p><a class="source-toggle" href="#"
135
138
  onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
136
139
  <div class="method-source-code" id="M000005-source">
137
140
  <pre>
138
- <span class="ruby-comment cmt"># File lib/stampable.rb, line 68</span>
139
- 68: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stampable</span>(<span class="ruby-identifier">options</span> = {})
140
- 69: <span class="ruby-identifier">defaults</span> = {
141
- 70: <span class="ruby-identifier">:stamper_class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:user</span>,
142
- 71: <span class="ruby-identifier">:creator_attribute</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Ddb</span><span class="ruby-operator">::</span><span class="ruby-constant">Userstamp</span>.<span class="ruby-identifier">compatibility_mode</span> <span class="ruby-value">? </span><span class="ruby-operator">:</span><span class="ruby-identifier">created_by</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:creator_id</span>,
143
- 72: <span class="ruby-identifier">:updater_attribute</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Ddb</span><span class="ruby-operator">::</span><span class="ruby-constant">Userstamp</span>.<span class="ruby-identifier">compatibility_mode</span> <span class="ruby-value">? </span><span class="ruby-operator">:</span><span class="ruby-identifier">updated_by</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:updater_id</span>,
144
- 73: <span class="ruby-identifier">:deleter_attribute</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Ddb</span><span class="ruby-operator">::</span><span class="ruby-constant">Userstamp</span>.<span class="ruby-identifier">compatibility_mode</span> <span class="ruby-value">? </span><span class="ruby-operator">:</span><span class="ruby-identifier">deleted_by</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:deleter_id</span>
145
- 74: }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
146
- 75:
147
- 76: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stamper_class_name</span> = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:stamper_class_name</span>].<span class="ruby-identifier">to_sym</span>
148
- 77: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">creator_attribute</span> = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:creator_attribute</span>].<span class="ruby-identifier">to_sym</span>
149
- 78: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">updater_attribute</span> = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:updater_attribute</span>].<span class="ruby-identifier">to_sym</span>
150
- 79: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">deleter_attribute</span> = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:deleter_attribute</span>].<span class="ruby-identifier">to_sym</span>
141
+ <span class="ruby-comment cmt"># File lib/stampable.rb, line 71</span>
142
+ 71: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stampable</span>(<span class="ruby-identifier">options</span> = {})
143
+ 72: <span class="ruby-identifier">compatability</span> = <span class="ruby-constant">Ddb</span><span class="ruby-operator">::</span><span class="ruby-constant">Userstamp</span>.<span class="ruby-identifier">compatibility_mode</span>
144
+ 73: <span class="ruby-identifier">defaults</span> = {
145
+ 74: <span class="ruby-identifier">:stamper_class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:user</span>,
146
+ 75: <span class="ruby-identifier">:creator_attribute</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-identifier">compatability</span> <span class="ruby-value">? </span><span class="ruby-operator">:</span><span class="ruby-identifier">created_by</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:creator_id</span>),
147
+ 76: <span class="ruby-identifier">:updater_attribute</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-identifier">compatability</span> <span class="ruby-value">? </span><span class="ruby-operator">:</span><span class="ruby-identifier">updated_by</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:updater_id</span>),
148
+ 77: <span class="ruby-identifier">:deleter_attribute</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-identifier">compatability</span> <span class="ruby-value">? </span><span class="ruby-operator">:</span><span class="ruby-identifier">deleted_by</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:deleter_id</span>),
149
+ 78: <span class="ruby-identifier">:deleter</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-operator">!</span><span class="ruby-operator">!</span>(<span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:deleter_attribute</span>) <span class="ruby-keyword kw">or</span> <span class="ruby-keyword kw">defined?</span>(<span class="ruby-constant">Caboose</span><span class="ruby-operator">::</span><span class="ruby-constant">Acts</span><span class="ruby-operator">::</span><span class="ruby-constant">Paranoid</span>))
150
+ 79: }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
151
151
  80:
152
- 81: <span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
153
- 82: <span class="ruby-identifier">belongs_to</span> <span class="ruby-identifier">:creator</span>, <span class="ruby-identifier">:class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stamper_class_name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">singularize</span>.<span class="ruby-identifier">camelize</span>,
154
- 83: <span class="ruby-identifier">:foreign_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">creator_attribute</span>
155
- 84:
156
- 85: <span class="ruby-identifier">belongs_to</span> <span class="ruby-identifier">:updater</span>, <span class="ruby-identifier">:class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stamper_class_name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">singularize</span>.<span class="ruby-identifier">camelize</span>,
157
- 86: <span class="ruby-identifier">:foreign_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">updater_attribute</span>
158
- 87:
159
- 88: <span class="ruby-identifier">before_save</span> <span class="ruby-identifier">:set_updater_attribute</span>
160
- 89: <span class="ruby-identifier">before_create</span> <span class="ruby-identifier">:set_creator_attribute</span>
161
- 90:
162
- 91: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span>(<span class="ruby-constant">Caboose</span><span class="ruby-operator">::</span><span class="ruby-constant">Acts</span><span class="ruby-operator">::</span><span class="ruby-constant">Paranoid</span>)
163
- 92: <span class="ruby-identifier">belongs_to</span> <span class="ruby-identifier">:deleter</span>, <span class="ruby-identifier">:class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stamper_class_name</span>,
164
- 93: <span class="ruby-identifier">:foreign_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">deleter_attribute</span>
165
- 94: <span class="ruby-identifier">before_destroy</span> <span class="ruby-identifier">:set_deleter_attribute</span>
166
- 95: <span class="ruby-keyword kw">end</span>
167
- 96: <span class="ruby-keyword kw">end</span>
168
- 97: <span class="ruby-keyword kw">end</span>
152
+ 81: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stamper_class_name</span> = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:stamper_class_name</span>].<span class="ruby-identifier">to_sym</span>
153
+ 82: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">creator_attribute</span> = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:creator_attribute</span>].<span class="ruby-identifier">to_sym</span>
154
+ 83: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">updater_attribute</span> = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:updater_attribute</span>].<span class="ruby-identifier">to_sym</span>
155
+ 84: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">deleter_attribute</span> = <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:deleter_attribute</span>].<span class="ruby-identifier">to_sym</span>
156
+ 85:
157
+ 86: <span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
158
+ 87: <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">stamper_class_name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">singularize</span>.<span class="ruby-identifier">camelize</span>
159
+ 88: <span class="ruby-identifier">belongs_to</span> <span class="ruby-identifier">:creator</span>, <span class="ruby-identifier">:class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">:foreign_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">creator_attribute</span>
160
+ 89: <span class="ruby-identifier">belongs_to</span> <span class="ruby-identifier">:updater</span>, <span class="ruby-identifier">:class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">:foreign_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">updater_attribute</span>
161
+ 90:
162
+ 91: <span class="ruby-identifier">before_save</span> <span class="ruby-identifier">:set_updater_attribute</span>
163
+ 92: <span class="ruby-identifier">before_create</span> <span class="ruby-identifier">:set_creator_attribute</span>
164
+ 93:
165
+ 94: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">defaults</span>[<span class="ruby-identifier">:deleter</span>]
166
+ 95: <span class="ruby-identifier">belongs_to</span> <span class="ruby-identifier">:deleter</span>, <span class="ruby-identifier">:class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">klass</span>, <span class="ruby-identifier">:foreign_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">deleter_attribute</span>
167
+ 96: <span class="ruby-identifier">before_destroy</span> <span class="ruby-identifier">:set_deleter_attribute</span>
168
+ 97: <span class="ruby-keyword kw">end</span>
169
+ 98: <span class="ruby-keyword kw">end</span>
170
+ 99: <span class="ruby-keyword kw">end</span>
169
171
  </pre>
170
172
  </div>
171
173
  </div>
@@ -195,13 +197,14 @@ Temporarily allows you to turn stamping off. For example:
195
197
  onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
196
198
  <div class="method-source-code" id="M000006-source">
197
199
  <pre>
198
- <span class="ruby-comment cmt"># File lib/stampable.rb, line 106</span>
199
- 106: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">without_stamps</span>
200
- 107: <span class="ruby-identifier">original_value</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">record_userstamp</span>
201
- 108: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">record_userstamp</span> = <span class="ruby-keyword kw">false</span>
202
- 109: <span class="ruby-keyword kw">yield</span>
203
- 110: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">record_userstamp</span> = <span class="ruby-identifier">original_value</span>
204
- 111: <span class="ruby-keyword kw">end</span>
200
+ <span class="ruby-comment cmt"># File lib/stampable.rb, line 108</span>
201
+ 108: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">without_stamps</span>
202
+ 109: <span class="ruby-identifier">original_value</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">record_userstamp</span>
203
+ 110: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">record_userstamp</span> = <span class="ruby-keyword kw">false</span>
204
+ 111: <span class="ruby-keyword kw">yield</span>
205
+ 112: <span class="ruby-keyword kw">ensure</span>
206
+ 113: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">record_userstamp</span> = <span class="ruby-identifier">original_value</span>
207
+ 114: <span class="ruby-keyword kw">end</span>
205
208
  </pre>
206
209
  </div>
207
210
  </div>
@@ -151,7 +151,7 @@ for the current request.
151
151
  <pre>
152
152
  <span class="ruby-comment cmt"># File lib/stamper.rb, line 30</span>
153
153
  30: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stamper</span>
154
- 31: <span class="ruby-identifier">find</span>(<span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-node">&quot;#{self.to_s.downcase}_#{self.object_id}_stamper&quot;</span>])
154
+ 31: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-node">&quot;#{self.to_s.downcase}_#{self.object_id}_stamper&quot;</span>]
155
155
  32: <span class="ruby-keyword kw">end</span>
156
156
  </pre>
157
157
  </div>
@@ -0,0 +1,118 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: Userstamp</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">Userstamp</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/userstamp_rb.html">
59
+ lib/userstamp.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+
76
+
77
+ </div>
78
+
79
+
80
+ </div>
81
+
82
+
83
+ <!-- if includes -->
84
+
85
+ <div id="section">
86
+
87
+
88
+ <div id="constants-list">
89
+ <h3 class="section-bar">Constants</h3>
90
+
91
+ <div class="name-list">
92
+ <table summary="Constants">
93
+ <tr class="top-aligned-row context-row">
94
+ <td class="context-item-name">VERSION</td>
95
+ <td>=</td>
96
+ <td class="context-item-value">File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip</td>
97
+ </tr>
98
+ </table>
99
+ </div>
100
+ </div>
101
+
102
+
103
+
104
+
105
+
106
+
107
+ <!-- if method_list -->
108
+
109
+
110
+ </div>
111
+
112
+
113
+ <div id="validator-badges">
114
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
115
+ </div>
116
+
117
+ </body>
118
+ </html>