jeremyw-paper_trail 1.2.12 → 1.2.14
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/paper_trail.rb +10 -6
- data/lib/paper_trail/config.rb +10 -0
- data/lib/paper_trail/has_paper_trail.rb +19 -15
- data/paper_trail.gemspec +5 -4
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.13
|
data/lib/paper_trail.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'paper_trail/config'
|
2
3
|
require 'paper_trail/has_paper_trail'
|
3
4
|
require 'paper_trail/version'
|
4
5
|
|
5
6
|
module PaperTrail
|
6
|
-
@@enabled = true
|
7
7
|
@@whodunnit = nil
|
8
8
|
|
9
|
+
def self.config
|
10
|
+
@@config ||= PaperTrail::Config.instance
|
11
|
+
end
|
12
|
+
|
9
13
|
def self.included(base)
|
10
14
|
base.before_filter :set_whodunnit
|
11
15
|
end
|
12
16
|
|
13
17
|
def self.enabled=(value)
|
14
|
-
|
18
|
+
PaperTrail.config.enabled = value
|
15
19
|
end
|
16
|
-
|
20
|
+
|
17
21
|
def self.enabled?
|
18
|
-
|
22
|
+
!!PaperTrail.config.enabled
|
19
23
|
end
|
20
|
-
|
24
|
+
|
21
25
|
def self.whodunnit
|
22
26
|
@@whodunnit.respond_to?(:call) ? @@whodunnit.call : @@whodunnit
|
23
27
|
end
|
@@ -33,7 +37,7 @@ module PaperTrail
|
|
33
37
|
self.send :current_user rescue nil
|
34
38
|
}
|
35
39
|
end
|
36
|
-
|
40
|
+
|
37
41
|
end
|
38
42
|
|
39
43
|
ActionController::Base.send :include, PaperTrail
|
@@ -8,7 +8,7 @@ module PaperTrail
|
|
8
8
|
module ClassMethods
|
9
9
|
def has_paper_trail
|
10
10
|
send :include, InstanceMethods
|
11
|
-
|
11
|
+
|
12
12
|
cattr_accessor :paper_trail_active
|
13
13
|
self.paper_trail_active = true
|
14
14
|
|
@@ -48,19 +48,19 @@ module PaperTrail
|
|
48
48
|
:object => object_to_string(previous_version),
|
49
49
|
:whodunnit => PaperTrail.whodunnit) if self.class.paper_trail_active && PaperTrail.enabled?
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
# Returns the object at the version that was valid at the given timestamp.
|
53
53
|
def version_at timestamp
|
54
54
|
# short-circuit if the current state is valid
|
55
55
|
return self if self.updated_at < timestamp
|
56
|
-
|
56
|
+
|
57
57
|
version = versions.first(
|
58
|
-
:conditions => ['created_at < ?', timestamp],
|
58
|
+
:conditions => ['created_at < ?', timestamp],
|
59
59
|
:order => 'created_at DESC')
|
60
60
|
version.reify if version
|
61
61
|
end
|
62
62
|
|
63
|
-
# Walk the versions to construct an audit trail of the edits made
|
63
|
+
# Walk the versions to construct an audit trail of the edits made
|
64
64
|
# over time, and by whom.
|
65
65
|
def audit_trail options={}
|
66
66
|
options[:attributes_to_ignore] ||= %w(updated_at)
|
@@ -77,11 +77,11 @@ module PaperTrail
|
|
77
77
|
attributes_before = yaml_to_hash(previous_version.object)
|
78
78
|
|
79
79
|
# remove some attributes that we don't need to report
|
80
|
-
[attributes_before, attributes_after].each do |hash|
|
80
|
+
[attributes_before, attributes_after].each do |hash|
|
81
81
|
hash.reject! { |k,v| k.in? Array(options[:attributes_to_ignore]) }
|
82
82
|
end
|
83
83
|
|
84
|
-
audit_trail << {
|
84
|
+
audit_trail << {
|
85
85
|
:event => previous_version.event,
|
86
86
|
:changed_by => transform_whodunnit(previous_version.whodunnit),
|
87
87
|
:changed_at => previous_version.created_at,
|
@@ -91,14 +91,14 @@ module PaperTrail
|
|
91
91
|
|
92
92
|
audit_trail
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
protected
|
96
96
|
|
97
97
|
def transform_whodunnit(whodunnit)
|
98
98
|
whodunnit
|
99
99
|
end
|
100
|
-
|
101
|
-
|
100
|
+
|
101
|
+
|
102
102
|
private
|
103
103
|
|
104
104
|
def previous_version
|
@@ -113,13 +113,13 @@ module PaperTrail
|
|
113
113
|
def object_to_string(object)
|
114
114
|
object.attributes.to_yaml
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def yaml_to_hash(yaml)
|
118
118
|
return {} if yaml.nil?
|
119
119
|
YAML::load(yaml).to_hash
|
120
120
|
end
|
121
121
|
|
122
|
-
# Returns an array of hashes, where each hash specifies the +:attribute+,
|
122
|
+
# Returns an array of hashes, where each hash specifies the +:attribute+,
|
123
123
|
# value +:before+ the change, and value +:after+ the change.
|
124
124
|
def differences(before, after)
|
125
125
|
before.diff(after).keys.sort.inject([]) do |diffs, k|
|
@@ -129,9 +129,13 @@ module PaperTrail
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def versions_including_current_in_descending_order
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
if self.new_record?
|
133
|
+
v = Version.all(:order => 'created_at desc', :conditions => {:item_id => id, :item_type => self.class.name})
|
134
|
+
else
|
135
|
+
v = self.versions.dup
|
136
|
+
end
|
137
|
+
v << Version.new(:event => 'update',
|
138
|
+
:object => object_to_string(self),
|
135
139
|
:created_at => self.updated_at)
|
136
140
|
v.reverse # newest first
|
137
141
|
end
|
data/paper_trail.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{paper_trail}
|
5
|
-
s.version = "1.2.
|
4
|
+
s.name = %q{jeremyw-paper_trail}
|
5
|
+
s.version = "1.2.14"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Andy Stewart", "Jeremy Weiskotten", "Joe Lind"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-10-02}
|
10
10
|
s.email = %q{jeremy@weiskotten.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"README.md"
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
"init.rb",
|
24
24
|
"install.rb",
|
25
25
|
"lib/paper_trail.rb",
|
26
|
+
"lib/paper_trail/config.rb",
|
26
27
|
"lib/paper_trail/has_paper_trail.rb",
|
27
28
|
"lib/paper_trail/version.rb",
|
28
29
|
"paper_trail.gemspec",
|
@@ -55,7 +56,7 @@ Gem::Specification.new do |s|
|
|
55
56
|
# if s.respond_to? :specification_version then
|
56
57
|
# current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
57
58
|
# s.specification_version = 2
|
58
|
-
#
|
59
|
+
#
|
59
60
|
# if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
60
61
|
# else
|
61
62
|
# end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jeremyw-paper_trail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Stewart
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2009-
|
14
|
+
date: 2009-10-02 00:00:00 -04:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- init.rb
|
36
36
|
- install.rb
|
37
37
|
- lib/paper_trail.rb
|
38
|
+
- lib/paper_trail/config.rb
|
38
39
|
- lib/paper_trail/has_paper_trail.rb
|
39
40
|
- lib/paper_trail/version.rb
|
40
41
|
- paper_trail.gemspec
|
@@ -50,7 +51,8 @@ files:
|
|
50
51
|
- uninstall.rb
|
51
52
|
has_rdoc: true
|
52
53
|
homepage: http://github.com/jeremyw/paper_trail
|
53
|
-
licenses:
|
54
|
+
licenses: []
|
55
|
+
|
54
56
|
post_install_message:
|
55
57
|
rdoc_options:
|
56
58
|
- --charset=UTF-8
|
@@ -73,7 +75,7 @@ requirements: []
|
|
73
75
|
rubyforge_project:
|
74
76
|
rubygems_version: 1.3.5
|
75
77
|
signing_key:
|
76
|
-
specification_version:
|
78
|
+
specification_version: 3
|
77
79
|
summary: Track changes to your models' data. Good for auditing or versioning.
|
78
80
|
test_files:
|
79
81
|
- test/paper_trail_controller_test.rb
|