grosser-userstamp 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. data/CHANGELOG +26 -0
  2. data/LICENSE +20 -0
  3. data/README +179 -0
  4. data/Rakefile +36 -0
  5. data/init.rb +1 -0
  6. data/lib/ddb/userstamp.rb +44 -0
  7. data/lib/ddb/userstamp/migration_helper.rb +19 -0
  8. data/lib/ddb/userstamp/stampable.rb +151 -0
  9. data/lib/ddb/userstamp/stamper.rb +43 -0
  10. data/lib/userstamp.rb +8 -0
  11. data/rdoc/classes/Ddb/Controller.html +111 -0
  12. data/rdoc/classes/Ddb/Controller/Userstamp.html +125 -0
  13. data/rdoc/classes/Ddb/Controller/Userstamp/InstanceMethods.html +105 -0
  14. data/rdoc/classes/Ddb/Userstamp.html +121 -0
  15. data/rdoc/classes/Ddb/Userstamp/MigrationHelper.html +111 -0
  16. data/rdoc/classes/Ddb/Userstamp/MigrationHelper/InstanceMethods.html +142 -0
  17. data/rdoc/classes/Ddb/Userstamp/Stampable.html +128 -0
  18. data/rdoc/classes/Ddb/Userstamp/Stampable/ClassMethods.html +222 -0
  19. data/rdoc/classes/Ddb/Userstamp/Stamper.html +112 -0
  20. data/rdoc/classes/Ddb/Userstamp/Stamper/ClassMethods.html +142 -0
  21. data/rdoc/classes/Ddb/Userstamp/Stamper/InstanceMethods.html +207 -0
  22. data/rdoc/files/CHANGELOG.html +137 -0
  23. data/rdoc/files/LICENSE.html +129 -0
  24. data/rdoc/files/README.html +341 -0
  25. data/rdoc/files/lib/ddb/userstamp/migration_helper_rb.html +101 -0
  26. data/rdoc/files/lib/ddb/userstamp/stampable_rb.html +101 -0
  27. data/rdoc/files/lib/ddb/userstamp/stamper_rb.html +101 -0
  28. data/rdoc/files/lib/ddb/userstamp_rb.html +101 -0
  29. data/rdoc/files/lib/userstamp_rb.html +114 -0
  30. data/test/compatibility_stamping_test.rb +63 -0
  31. data/test/controllers/posts_controller.rb +26 -0
  32. data/test/controllers/users_controller.rb +12 -0
  33. data/test/controllers/userstamp_controller.rb +9 -0
  34. data/test/database.yml +4 -0
  35. data/test/fixtures/comments.yml +16 -0
  36. data/test/fixtures/people.yml +11 -0
  37. data/test/fixtures/posts.yml +9 -0
  38. data/test/fixtures/users.yml +7 -0
  39. data/test/helpers/functional_test_helper.rb +37 -0
  40. data/test/helpers/unit_test_helper.rb +29 -0
  41. data/test/models/comment.rb +4 -0
  42. data/test/models/person.rb +3 -0
  43. data/test/models/ping.rb +7 -0
  44. data/test/models/post.rb +4 -0
  45. data/test/models/user.rb +3 -0
  46. data/test/schema.rb +56 -0
  47. data/test/stamping_test.rb +110 -0
  48. data/test/userstamp_controller_test.rb +118 -0
  49. data/userstamp.gemspec +53 -0
  50. metadata +180 -0
@@ -0,0 +1,43 @@
1
+ module Ddb #:nodoc:
2
+ module Userstamp
3
+ module Stamper
4
+ def self.included(base) # :nodoc:
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def model_stamper
10
+ # don't allow multiple calls
11
+ return if self.included_modules.include?(Ddb::Userstamp::Stamper::InstanceMethods)
12
+ send(:extend, Ddb::Userstamp::Stamper::InstanceMethods)
13
+ end
14
+ end
15
+
16
+ module InstanceMethods
17
+ # Used to set the stamper for a particular request. See the Userstamp module for more
18
+ # details on how to use this method.
19
+ def stamper=(object)
20
+ object_stamper = if object.is_a?(ActiveRecord::Base)
21
+ object.send("#{object.class.primary_key}".to_sym)
22
+ else
23
+ object
24
+ end
25
+
26
+ Thread.current["#{self.to_s.downcase}_#{self.object_id}_stamper"] = object_stamper
27
+ end
28
+
29
+ # Retrieves the existing stamper for the current request.
30
+ def stamper
31
+ Thread.current["#{self.to_s.downcase}_#{self.object_id}_stamper"]
32
+ end
33
+
34
+ # Sets the stamper back to +nil+ to prepare for the next request.
35
+ def reset_stamper
36
+ Thread.current["#{self.to_s.downcase}_#{self.object_id}_stamper"] = nil
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ ActiveRecord::Base.send(:include, Ddb::Userstamp::Stamper) if defined?(ActiveRecord)
data/lib/userstamp.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'activesupport'
2
+ require 'activerecord'
3
+ require 'actionpack'
4
+
5
+ require 'ddb/userstamp/stamper'
6
+ require 'ddb/userstamp/stampable'
7
+ require 'ddb/userstamp'
8
+ require 'ddb/userstamp/migration_helper'
@@ -0,0 +1,111 @@
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: Ddb::Controller</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">Ddb::Controller</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/ddb/userstamp_rb.html">
59
+ lib/ddb/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
+ <div id="class-list">
88
+ <h3 class="section-bar">Classes and Modules</h3>
89
+
90
+ Module <a href="Controller/Userstamp.html" class="link">Ddb::Controller::Userstamp</a><br />
91
+
92
+ </div>
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+ <!-- if method_list -->
101
+
102
+
103
+ </div>
104
+
105
+
106
+ <div id="validator-badges">
107
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
108
+ </div>
109
+
110
+ </body>
111
+ </html>
@@ -0,0 +1,125 @@
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: Ddb::Controller::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">Ddb::Controller::Userstamp</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../../files/lib/ddb/userstamp_rb.html">
59
+ lib/ddb/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
+ <div id="description">
76
+ <p>
77
+ The <a href="Userstamp.html">Userstamp</a> module, when included into a
78
+ controller, adds a before filter (named <tt>set_stamper</tt>) and an after
79
+ filter (name <tt>reset_stamper</tt>). These methods assume a couple of
80
+ things, but can be re-implemented in your controller to better suite your
81
+ application.
82
+ </p>
83
+ <p>
84
+ See the documentation for <tt>set_stamper</tt> and <tt>reset_stamper</tt>
85
+ for specific implementation details.
86
+ </p>
87
+
88
+ </div>
89
+
90
+
91
+ </div>
92
+
93
+
94
+ </div>
95
+
96
+
97
+ <!-- if includes -->
98
+
99
+ <div id="section">
100
+
101
+ <div id="class-list">
102
+ <h3 class="section-bar">Classes and Modules</h3>
103
+
104
+ Module <a href="Userstamp/InstanceMethods.html" class="link">Ddb::Controller::Userstamp::InstanceMethods</a><br />
105
+
106
+ </div>
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+ <!-- if method_list -->
115
+
116
+
117
+ </div>
118
+
119
+
120
+ <div id="validator-badges">
121
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
122
+ </div>
123
+
124
+ </body>
125
+ </html>
@@ -0,0 +1,105 @@
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: Ddb::Controller::Userstamp::InstanceMethods</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">Ddb::Controller::Userstamp::InstanceMethods</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../../../files/lib/ddb/userstamp_rb.html">
59
+ lib/ddb/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
+
89
+
90
+
91
+
92
+
93
+
94
+ <!-- if method_list -->
95
+
96
+
97
+ </div>
98
+
99
+
100
+ <div id="validator-badges">
101
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
102
+ </div>
103
+
104
+ </body>
105
+ </html>
@@ -0,0 +1,121 @@
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: Ddb::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">Ddb::Userstamp</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/ddb/userstamp/stampable_rb.html">
59
+ lib/ddb/userstamp/stampable.rb
60
+ </a>
61
+ <br />
62
+ <a href="../../files/lib/ddb/userstamp/migration_helper_rb.html">
63
+ lib/ddb/userstamp/migration_helper.rb
64
+ </a>
65
+ <br />
66
+ <a href="../../files/lib/ddb/userstamp/stamper_rb.html">
67
+ lib/ddb/userstamp/stamper.rb
68
+ </a>
69
+ <br />
70
+ </td>
71
+ </tr>
72
+
73
+ </table>
74
+ </div>
75
+ <!-- banner header -->
76
+
77
+ <div id="bodyContent">
78
+
79
+
80
+
81
+ <div id="contextContent">
82
+
83
+
84
+
85
+ </div>
86
+
87
+
88
+ </div>
89
+
90
+
91
+ <!-- if includes -->
92
+
93
+ <div id="section">
94
+
95
+ <div id="class-list">
96
+ <h3 class="section-bar">Classes and Modules</h3>
97
+
98
+ Module <a href="Userstamp/MigrationHelper.html" class="link">Ddb::Userstamp::MigrationHelper</a><br />
99
+ Module <a href="Userstamp/Stampable.html" class="link">Ddb::Userstamp::Stampable</a><br />
100
+ Module <a href="Userstamp/Stamper.html" class="link">Ddb::Userstamp::Stamper</a><br />
101
+
102
+ </div>
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ <!-- if method_list -->
111
+
112
+
113
+ </div>
114
+
115
+
116
+ <div id="validator-badges">
117
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
118
+ </div>
119
+
120
+ </body>
121
+ </html>