originator 3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +31 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE +20 -0
  5. data/Rakefile +30 -0
  6. data/Readme.rdoc +162 -0
  7. data/VERSION +1 -0
  8. data/lib/migration_helper.rb +19 -0
  9. data/lib/stampable.rb +152 -0
  10. data/lib/stamper.rb +43 -0
  11. data/lib/userstamp.rb +52 -0
  12. data/originator.gemspec +84 -0
  13. data/rdoc/classes/Ddb/Controller.html +111 -0
  14. data/rdoc/classes/Ddb/Controller/Userstamp.html +125 -0
  15. data/rdoc/classes/Ddb/Controller/Userstamp/InstanceMethods.html +105 -0
  16. data/rdoc/classes/Ddb/Userstamp.html +121 -0
  17. data/rdoc/classes/Ddb/Userstamp/MigrationHelper.html +111 -0
  18. data/rdoc/classes/Ddb/Userstamp/MigrationHelper/InstanceMethods.html +142 -0
  19. data/rdoc/classes/Ddb/Userstamp/Stampable.html +128 -0
  20. data/rdoc/classes/Ddb/Userstamp/Stampable/ClassMethods.html +225 -0
  21. data/rdoc/classes/Ddb/Userstamp/Stamper.html +112 -0
  22. data/rdoc/classes/Ddb/Userstamp/Stamper/ClassMethods.html +142 -0
  23. data/rdoc/classes/Ddb/Userstamp/Stamper/InstanceMethods.html +207 -0
  24. data/rdoc/classes/Userstamp.html +118 -0
  25. data/rdoc/created.rid +1 -0
  26. data/rdoc/files/CHANGELOG.html +137 -0
  27. data/rdoc/files/LICENSE.html +129 -0
  28. data/rdoc/files/Readme_rdoc.html +301 -0
  29. data/rdoc/files/lib/migration_helper_rb.html +101 -0
  30. data/rdoc/files/lib/stampable_rb.html +101 -0
  31. data/rdoc/files/lib/stamper_rb.html +101 -0
  32. data/rdoc/files/lib/userstamp_rb.html +110 -0
  33. data/rdoc/fr_class_index.html +38 -0
  34. data/rdoc/fr_file_index.html +33 -0
  35. data/rdoc/fr_method_index.html +33 -0
  36. data/rdoc/index.html +24 -0
  37. data/rdoc/rdoc-style.css +208 -0
  38. data/test/compatibility_stamping_test.rb +69 -0
  39. data/test/controllers/posts_controller.rb +26 -0
  40. data/test/controllers/users_controller.rb +12 -0
  41. data/test/controllers/userstamp_controller.rb +9 -0
  42. data/test/helper.rb +61 -0
  43. data/test/models/comment.rb +5 -0
  44. data/test/models/foo.rb +3 -0
  45. data/test/models/person.rb +3 -0
  46. data/test/models/post.rb +13 -0
  47. data/test/models/user.rb +3 -0
  48. data/test/schema.rb +54 -0
  49. data/test/stamping_test.rb +138 -0
  50. data/test/userstamp_controller_test.rb +103 -0
  51. data/test/userstamp_test.rb +7 -0
  52. metadata +138 -0
data/lib/userstamp.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'stamper'
2
+ require 'stampable'
3
+ require 'migration_helper'
4
+
5
+ module Userstamp
6
+ VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
7
+ end
8
+
9
+ module Ddb
10
+ module Controller
11
+ # The Userstamp module, when included into a controller, adds a before filter
12
+ # (named <tt>set_stamper</tt>) and an after filter (name <tt>reset_stamper</tt>).
13
+ # These methods assume a couple of things, but can be re-implemented in your
14
+ # controller to better suite your application.
15
+ #
16
+ # See the documentation for <tt>set_stamper</tt> and <tt>reset_stamper</tt> for
17
+ # specific implementation details.
18
+ module Userstamp
19
+ def self.included(base) # :nodoc:
20
+ base.send :include, InstanceMethods
21
+ base.before_action :set_stamper
22
+ base.after_action :reset_stamper
23
+ end
24
+
25
+ module InstanceMethods
26
+ private
27
+ # The <tt>set_stamper</tt> method as implemented here assumes a couple
28
+ # of things. First, that you are using a +User+ model as the stamper
29
+ # and second that your controller has a <tt>current_user</tt> method
30
+ # that contains the currently logged in stamper. If either of these
31
+ # are not the case in your application you will want to manually add
32
+ # your own implementation of this method to the private section of
33
+ # the controller where you are including the Userstamp module.
34
+ def set_stamper
35
+ User.stamper = self.current_user
36
+ end
37
+
38
+ # The <tt>reset_stamper</tt> method as implemented here assumes that a
39
+ # +User+ model is being used as the stamper. If this is not the case then
40
+ # you will need to manually add your own implementation of this method to
41
+ # the private section of the controller where you are including the
42
+ # Userstamp module.
43
+ def reset_stamper
44
+ User.reset_stamper
45
+ end
46
+ #end private
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ ActionController::Base.send(:include, Ddb::Controller) if defined?(ActionController)
@@ -0,0 +1,84 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "originator"
5
+ s.version = File.read(File.join(File.dirname(__FILE__), 'VERSION')).strip
6
+
7
+ s.authors = ["DeLynn Berry", "Thomas von Deyen"]
8
+ s.homepage = "https://github.com/AlchemyCMS/originator"
9
+ s.email = ["thomas@vondeyen.com"]
10
+ s.summary = "Adds originator attributes to your ActiveRecord models."
11
+ s.description = "This gem extends ActiveRecord::Base to add automatic updating of created_by and updated_by attributes of your models in much the same way that the ActiveRecord::Timestamp module updates created_(at/on) and updated_(at/on) attributes."
12
+ s.licenses = ["MIT"]
13
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
14
+
15
+ s.extra_rdoc_files = [
16
+ "LICENSE"
17
+ ]
18
+ s.files = [
19
+ "CHANGELOG",
20
+ "Gemfile",
21
+ "LICENSE",
22
+ "Rakefile",
23
+ "Readme.rdoc",
24
+ "VERSION",
25
+ "lib/migration_helper.rb",
26
+ "lib/stampable.rb",
27
+ "lib/stamper.rb",
28
+ "lib/userstamp.rb",
29
+ "originator.gemspec",
30
+ "rdoc/classes/Ddb/Controller.html",
31
+ "rdoc/classes/Ddb/Controller/Userstamp.html",
32
+ "rdoc/classes/Ddb/Controller/Userstamp/InstanceMethods.html",
33
+ "rdoc/classes/Ddb/Userstamp.html",
34
+ "rdoc/classes/Ddb/Userstamp/MigrationHelper.html",
35
+ "rdoc/classes/Ddb/Userstamp/MigrationHelper/InstanceMethods.html",
36
+ "rdoc/classes/Ddb/Userstamp/Stampable.html",
37
+ "rdoc/classes/Ddb/Userstamp/Stampable/ClassMethods.html",
38
+ "rdoc/classes/Ddb/Userstamp/Stamper.html",
39
+ "rdoc/classes/Ddb/Userstamp/Stamper/ClassMethods.html",
40
+ "rdoc/classes/Ddb/Userstamp/Stamper/InstanceMethods.html",
41
+ "rdoc/classes/Userstamp.html",
42
+ "rdoc/created.rid",
43
+ "rdoc/files/CHANGELOG.html",
44
+ "rdoc/files/LICENSE.html",
45
+ "rdoc/files/Readme_rdoc.html",
46
+ "rdoc/files/lib/migration_helper_rb.html",
47
+ "rdoc/files/lib/stampable_rb.html",
48
+ "rdoc/files/lib/stamper_rb.html",
49
+ "rdoc/files/lib/userstamp_rb.html",
50
+ "rdoc/fr_class_index.html",
51
+ "rdoc/fr_file_index.html",
52
+ "rdoc/fr_method_index.html",
53
+ "rdoc/index.html",
54
+ "rdoc/rdoc-style.css",
55
+ "test/compatibility_stamping_test.rb",
56
+ "test/controllers/posts_controller.rb",
57
+ "test/controllers/users_controller.rb",
58
+ "test/controllers/userstamp_controller.rb",
59
+ "test/helper.rb",
60
+ "test/models/comment.rb",
61
+ "test/models/foo.rb",
62
+ "test/models/person.rb",
63
+ "test/models/post.rb",
64
+ "test/models/user.rb",
65
+ "test/schema.rb",
66
+ "test/stamping_test.rb",
67
+ "test/userstamp_controller_test.rb",
68
+ "test/userstamp_test.rb"
69
+ ]
70
+ s.require_paths = ["lib"]
71
+ s.rubygems_version = "1.8.11"
72
+
73
+ s.add_runtime_dependency 'actionpack', '>= 4.0', '< 5.1'
74
+ s.add_runtime_dependency 'activerecord', '>= 4.0', '< 5.1'
75
+
76
+ if s.respond_to? :specification_version then
77
+ s.specification_version = 3
78
+
79
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
80
+ else
81
+ end
82
+ else
83
+ end
84
+ end
@@ -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/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
+ <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/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
+ <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/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
+
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>