GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Provides a history of attribute and association updates for models. This coincides with a versioning system (such as acts_as_versioned). When used in tandem, you get both a history of changes and a history of what changed.
Homepage: http://rubyforge.org/projects/ruby-shadow/
Clone URL: git://github.com/TheBreeze/shadow.git
Updated README, added TODO, updated method names.
TheBreeze (author)
Fri May 02 16:18:17 -0700 2008
commit  cc528304cc787245a0c58a5a49d6bbe1b9aa37ca
tree    c71d1de53b5b1ccc9a9ef37461592e11680fdfe7
parent  ca63fa36a9d2602c6e26109fa24469ca7341a4f8
0
...
1
2
3
4
5
 
6
7
8
9
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
12
13
 
...
1
2
3
 
 
4
5
6
7
8
 
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
53
0
@@ -1,13 +1,53 @@
0
 Shadow
0
 ======
0
 
0
-Introduction goes here.
0
-
0
+Provides a history of attribute and association updates for models. This coincides with a versioning system (such as acts_as_versioned). When used in tandem, you get both a history of changes and a history of what changed.
0
 
0
 Example
0
 =======
0
 
0
-Example goes here.
0
+# After creating your migrations (see TODO)
0
+
0
+# In your model
0
+
0
+class Vacation < ActiveRecord::Base
0
+ has_many :photos
0
+
0
+ # By default, shadows all :attributes and :associations. Here we're attaching a user, so we know who added a photo.
0
+ shadow :associations => :photos, :attach => :user
0
+end
0
+
0
+# In your controller (here we assume nested under VacationController)
0
+
0
+class PhotosController < ApplicationController
0
+ def create
0
+ @vacation = Vacation.find params[:vacation_id]
0
+
0
+ # This is where you attach the :user to the photo. If Photo doesn't have a user attribute or association, shadow
0
+ # will attach an attr_accessor to it and store it with the AssociationShadow record.
0
+ @photo = Photo.new params[:photo].merge(:user => current_user)
0
+
0
+ # You must either use the #association<<, #association.push, or #association.create for the shadow to be created.
0
+ if @vacation.photos << @photo
0
+ # success!
0
+ end
0
+ end
0
+end
0
+
0
+# In your view (displaying the updates in the show action of VacationController)
0
+
0
+<h1>Vacation Updates</h1>
0
+
0
+<% @vacation.association_updates.each do |update| -%>
0
+ <p><%= update.user.name %> <%= update.action %> <%= update.record.thumbnail %> to <%= update.association %></p>
0
+<% end -%>
0
+
0
+# Example result from view:
0
+
0
+<h1>Vacation Updates</h1>
0
+
0
+<p>Jordan added [photo thumbnail] to photos</p>
0
+
0
 
0
 
0
-Copyright (c) 2008 [name of plugin creator], released under the MIT license
0
+Copyright (c) 2008 Jordan Fowler, released under the MIT license
0
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
0
@@ -0,0 +1,40 @@
0
+TODO
0
+====
0
+
0
+- RSpec test coverage (currently only tested in application originally written for)
0
+
0
+- Need to define create_attribute_shadow_table and create_association_shadow_table, which will generate a migration for you.
0
+ Usage example:
0
+ Vacation.create_attribute_shadow_table # options include :attachments => [:user, ...] <- creates user_id
0
+ # Resulting table: vacation_attribute_shadows
0
+
0
+ Vacation.create_association_shadow_table # options include :attachments => [:user, ...] <- creates user_id
0
+ # Resulting table: vacation_association_shadows
0
+
0
+ # And (already defined)
0
+ Vacation.create_shadow_tables # subsequently calls create_shadow_attributes_table and create_shadow_associations_table
0
+
0
+ # This should generate:
0
+ class CreateVacationShadowTables < ActiveRecord::Migration
0
+ def self.up
0
+ create_table :vacation_attribute_shadows do |t|
0
+ t.text :updated_attributes
0
+ t.integer :version, :vacation_id, :user_id
0
+
0
+ t.timestamps
0
+ end
0
+
0
+ create_table :vacation_association_shadows do |t|
0
+ t.string :association, :action
0
+ t.integer :record_id, :record_version, :vacation_id, :user_id
0
+
0
+ t.timestamps
0
+ end
0
+ end
0
+
0
+ def self.down
0
+ drop_table :vacation_attribute_shadows
0
+ drop_table :vacation_association_shadows
0
+ end
0
+ end
0
+
0
\ No newline at end of file
...
162
163
164
165
166
 
 
167
168
169
...
173
174
175
176
177
 
 
178
179
180
...
185
186
187
188
189
 
 
190
191
192
...
162
163
164
 
 
165
166
167
168
169
...
173
174
175
 
 
176
177
178
179
180
...
185
186
187
 
 
188
189
190
191
192
0
@@ -162,8 +162,8 @@ module ActiveRecord
0
         end
0
 
0
         module ShadowClassMethods
0
- def create_shadowed_attributes_table
0
- # this should generate the (table_name)_shadowed_attributes table
0
+ def create_attribute_shadow_table
0
+ # this should generate the (table_name)_attribute_shadows table
0
 
0
             # [
0
             # table_name_prefix,
0
@@ -173,8 +173,8 @@ module ActiveRecord
0
             # ].join
0
           end
0
 
0
- def create_shadowed_associations_table
0
- # this should generate the (table_name)_shadowed_associations table
0
+ def create_association_shadow_table
0
+ # this should generate the (table_name)_association_shadows table
0
 
0
             # [
0
             # table_name_prefix,
0
@@ -185,8 +185,8 @@ module ActiveRecord
0
           end
0
 
0
           def create_shadow_tables
0
- create_shadow_attributes_table
0
- create_shadow_associations_table
0
+ create_attribute_shadow_table
0
+ create_association_shadow_table
0
           end
0
 
0
           protected

Comments

    No one has commented yet.