paper_trail 2.3.3 → 2.4.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.
- data/.gitignore +1 -0
- data/README.md +12 -2
- data/lib/paper_trail/version.rb +1 -0
- data/lib/paper_trail/version_number.rb +1 -1
- data/test/test_helper.rb +5 -0
- metadata +17 -17
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -456,7 +456,17 @@ You can store arbitrary model-level metadata alongside each version like this:
|
|
456
456
|
end
|
457
457
|
end
|
458
458
|
|
459
|
-
PaperTrail will call your proc with the current article and store the result in the `author_id` column of the `versions` table.
|
459
|
+
PaperTrail will call your proc with the current article and store the result in the `author_id` column of the `versions` table.
|
460
|
+
|
461
|
+
N.B. You must also:
|
462
|
+
|
463
|
+
* Add your metadata columns to the `versions` table.
|
464
|
+
* Declare your metadata columns using `attr_accessible` like this:
|
465
|
+
|
466
|
+
# config/initializers/paper_trail.rb
|
467
|
+
class Version < ActiveRecord::Base
|
468
|
+
attr_accessible :author_id, :word_count, :answer
|
469
|
+
end
|
460
470
|
|
461
471
|
Why would you do this? In this example, `author_id` is an attribute of `Article` and PaperTrail will store it anyway in serialized (YAML) form in the `object` column of the `version` record. But let's say you wanted to pull out all versions for a particular author; without the metadata you would have to deserialize (reify) each `version` object to see if belonged to the author in question. Clearly this is inefficient. Using the metadata you can find just those versions you want:
|
462
472
|
|
@@ -472,7 +482,7 @@ You can also store any information you like from your controller. Just override
|
|
472
482
|
end
|
473
483
|
end
|
474
484
|
|
475
|
-
Remember to add those extra columns to your `versions` table ;)
|
485
|
+
Remember to add those extra columns to your `versions` table and use `attr_accessible` ;)
|
476
486
|
|
477
487
|
|
478
488
|
## Diffing Versions
|
data/lib/paper_trail/version.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class Version < ActiveRecord::Base
|
2
2
|
belongs_to :item, :polymorphic => true
|
3
3
|
validates_presence_of :event
|
4
|
+
attr_accessible :item_type, :item_id, :event, :whodunnit, :object, :object_changes
|
4
5
|
|
5
6
|
def self.with_item_keys(item_type, item_id)
|
6
7
|
scoped(:conditions => { :item_type => item_type, :item_id => item_id })
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paper_trail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 2.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 2.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andy Stewart
|
@@ -15,13 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-29 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: rails
|
23
23
|
prerelease: false
|
24
|
-
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
@@ -31,11 +31,11 @@ dependencies:
|
|
31
31
|
- 3
|
32
32
|
version: "3"
|
33
33
|
type: :runtime
|
34
|
-
|
34
|
+
requirement: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: shoulda
|
37
37
|
prerelease: false
|
38
|
-
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - "="
|
@@ -47,11 +47,11 @@ dependencies:
|
|
47
47
|
- 3
|
48
48
|
version: 2.10.3
|
49
49
|
type: :development
|
50
|
-
|
50
|
+
requirement: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
52
|
name: sqlite3-ruby
|
53
53
|
prerelease: false
|
54
|
-
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
56
56
|
requirements:
|
57
57
|
- - ~>
|
@@ -62,11 +62,11 @@ dependencies:
|
|
62
62
|
- 2
|
63
63
|
version: "1.2"
|
64
64
|
type: :development
|
65
|
-
|
65
|
+
requirement: *id003
|
66
66
|
- !ruby/object:Gem::Dependency
|
67
67
|
name: capybara
|
68
68
|
prerelease: false
|
69
|
-
|
69
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
70
|
none: false
|
71
71
|
requirements:
|
72
72
|
- - ">="
|
@@ -78,11 +78,11 @@ dependencies:
|
|
78
78
|
- 0
|
79
79
|
version: 0.4.0
|
80
80
|
type: :development
|
81
|
-
|
81
|
+
requirement: *id004
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: turn
|
84
84
|
prerelease: false
|
85
|
-
|
85
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
88
88
|
- - ">="
|
@@ -92,7 +92,7 @@ dependencies:
|
|
92
92
|
- 0
|
93
93
|
version: "0"
|
94
94
|
type: :development
|
95
|
-
|
95
|
+
requirement: *id005
|
96
96
|
description: Track changes to your models' data. Good for auditing or versioning.
|
97
97
|
email: boss@airbladesoftware.com
|
98
98
|
executables: []
|
@@ -211,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
211
|
requirements: []
|
212
212
|
|
213
213
|
rubyforge_project:
|
214
|
-
rubygems_version: 1.
|
214
|
+
rubygems_version: 1.6.2
|
215
215
|
signing_key:
|
216
216
|
specification_version: 3
|
217
217
|
summary: Track changes to your models' data. Good for auditing or versioning.
|