simple_audit 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/README.markdown +30 -1
- data/Rakefile +1 -1
- data/TODO +2 -0
- data/lib/simple_audit/helper.rb +6 -5
- data/lib/simple_audit/simple_audit.rb +9 -2
- data/simple_audit.gemspec +4 -4
- metadata +5 -10
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -85,6 +85,35 @@ Audit ActiveRecord models. Somewhere in your (backend) views show the audit logs
|
|
85
85
|
<%= render_audits(@booking) %>
|
86
86
|
...
|
87
87
|
|
88
|
+
## Sample styling
|
89
|
+
.audits {
|
90
|
+
clear: both;
|
91
|
+
}
|
92
|
+
.audit {
|
93
|
+
-moz-border-radius:8px;
|
94
|
+
-webkit-border-radius: 8px;
|
95
|
+
background-color: #dfdfdf;
|
96
|
+
padding: 6px;
|
97
|
+
margin-bottom: 8px;
|
98
|
+
font-size: 12px;
|
99
|
+
}
|
100
|
+
.audit .action, .audit .user, .audit .timestamp{
|
101
|
+
float: left;
|
102
|
+
margin-right: 6px;
|
103
|
+
}
|
104
|
+
.audit .changes {
|
105
|
+
clear: both;
|
106
|
+
white-space: pre;
|
107
|
+
}
|
108
|
+
|
109
|
+
.audit .current {
|
110
|
+
margin-left: 6px;
|
111
|
+
}
|
112
|
+
.audit .previous {
|
113
|
+
margin-left: 6px;
|
114
|
+
text-decoration: line-through;
|
115
|
+
}
|
116
|
+
|
88
117
|
# Assumptions and limitations
|
89
118
|
|
90
119
|
* Your user model is called User and the current user User.current
|
@@ -93,7 +122,7 @@ Audit ActiveRecord models. Somewhere in your (backend) views show the audit logs
|
|
93
122
|
|
94
123
|
## Customize auditing
|
95
124
|
|
96
|
-
By default after each save, all model's attributes are saved in the audits table.
|
125
|
+
By default after each save, all model's attributes and `belongs_to` associations (their `id` and `to_s` on these) are saved in the audits table.
|
97
126
|
You can customize the data which is saved by supplying a block which will return all relevant data for the audited model.
|
98
127
|
|
99
128
|
# app/models/booking.rb
|
data/Rakefile
CHANGED
@@ -45,7 +45,7 @@ begin
|
|
45
45
|
gemspec.email = ["gabriel.tarnovan@cubus.ro", "mihai.tarnovan@cubus.ro"]
|
46
46
|
gemspec.homepage = "http://github.com/gtarnovan/simple_audit"
|
47
47
|
gemspec.authors = ["Gabriel Tarnovan", "Mihai Tarnovan"]
|
48
|
-
gemspec.version = "0.
|
48
|
+
gemspec.version = "0.2.0"
|
49
49
|
gemspec.files = gem_files
|
50
50
|
gemspec.test_files = test_files
|
51
51
|
|
data/TODO
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
* ORM agnosticism
|
4
4
|
|
5
5
|
# Functionality
|
6
|
+
* configure object used as current user
|
7
|
+
* fallback to :to_s for username_method
|
6
8
|
* provide some sort of UUID for audited models that identify these independently from the database provided ID.
|
7
9
|
in case of deletion and creation of a new entity with the same UUID, the audit trails of both entities could be bound.
|
8
10
|
e.g. for an invoice the UUID could be its number/series combination. when someone deletes an invoice and creates a new one
|
data/lib/simple_audit/helper.rb
CHANGED
@@ -15,21 +15,22 @@ module SimpleAudit #:nodoc:
|
|
15
15
|
content_tag(:div, l(audit.created_at), :class => "timestamp") +
|
16
16
|
content_tag(:div, :class => 'changes') do
|
17
17
|
changes = if older_audit.present?
|
18
|
-
audit.delta(older_audit).collect do |k, v|
|
18
|
+
audit.delta(older_audit).sort{|x,y| audited_model.class.human_attribute_name(x.first) <=> audited_model.class.human_attribute_name(y.first)}.collect do |k, v|
|
19
|
+
next if k.to_s == 'created_at' || k.to_s == 'updated_at'
|
19
20
|
"\n" +
|
20
21
|
audited_model.class.human_attribute_name(k) +
|
21
22
|
":" +
|
22
23
|
content_tag(:span, v.last, :class => 'current') +
|
23
|
-
content_tag(:span, v.first, :class => 'previous')
|
24
|
+
content_tag(:span, v.first, :class => 'previous')
|
24
25
|
end
|
25
26
|
else
|
26
|
-
audit.change_log.reject{|k, v| v.blank?}.collect {|k, v| "\n#{audited_model.class.human_attribute_name(k)}: #{v}"}
|
27
|
+
audit.change_log.sort{|x,y| audited_model.class.human_attribute_name(x.first) <=> audited_model.class.human_attribute_name(y.first)}.reject{|k, v| v.blank?}.collect {|k, v| "\n#{audited_model.class.human_attribute_name(k)}: #{v}"}
|
27
28
|
end
|
28
|
-
changes.join
|
29
|
+
raw changes.join
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
32
|
-
res
|
33
|
+
raw res
|
33
34
|
end
|
34
35
|
|
35
36
|
end
|
@@ -20,7 +20,7 @@ module SimpleAudit
|
|
20
20
|
#
|
21
21
|
# * <tt>username_method => symbol</tt> - Call this method on the current user to get the name
|
22
22
|
#
|
23
|
-
# With no block, all the attributes of the audited model will be logged.
|
23
|
+
# With no block, all the attributes and <tt>belongs_to</tt> associations (id and to_s) of the audited model will be logged.
|
24
24
|
#
|
25
25
|
# class Booking
|
26
26
|
# # this is equivalent to passing no block
|
@@ -49,7 +49,14 @@ module SimpleAudit
|
|
49
49
|
write_inheritable_attribute :username_method, (options[:username_method] || :name).to_sym
|
50
50
|
class_inheritable_reader :username_method
|
51
51
|
|
52
|
-
|
52
|
+
attributes_and_associations = proc do |record|
|
53
|
+
changes = record.attributes
|
54
|
+
record.class.reflect_on_all_associations(:belongs_to).each do |assoc|
|
55
|
+
changes[assoc.name] = record.send(assoc.name).to_s
|
56
|
+
end
|
57
|
+
changes
|
58
|
+
end
|
59
|
+
audit_changes_proc = block_given? ? block.to_proc : attributes_and_associations
|
53
60
|
write_inheritable_attribute :audit_changes, audit_changes_proc
|
54
61
|
class_inheritable_reader :audit_changes
|
55
62
|
|
data/simple_audit.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{simple_audit}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gabriel Tarnovan", "Mihai Tarnovan"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-05-03}
|
13
13
|
s.description = %q{ Provides a straightforward way for auditing changes on active record models, especially for composite entities.
|
14
14
|
Also provides helper methods for easily rendering an audit trail in Ruby on Rails views.
|
15
15
|
}
|
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
|
|
47
47
|
s.rdoc_options = ["--charset=UTF-8"]
|
48
48
|
s.require_paths = ["lib"]
|
49
49
|
s.rubyforge_project = %q{simple_audit}
|
50
|
-
s.rubygems_version = %q{1.3.
|
50
|
+
s.rubygems_version = %q{1.3.6}
|
51
51
|
s.summary = %q{Simple auditing solution for ActiveRecord models}
|
52
52
|
s.test_files = [
|
53
53
|
"test/fixtures",
|
@@ -62,7 +62,7 @@ Gem::Specification.new do |s|
|
|
62
62
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
63
63
|
s.specification_version = 3
|
64
64
|
|
65
|
-
if Gem::Version.new(Gem::
|
65
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
66
66
|
else
|
67
67
|
end
|
68
68
|
else
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_audit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 25
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Gabriel Tarnovan
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date:
|
18
|
+
date: 2011-05-03 00:00:00 +03:00
|
20
19
|
default_executable:
|
21
20
|
dependencies: []
|
22
21
|
|
@@ -65,27 +64,23 @@ rdoc_options:
|
|
65
64
|
require_paths:
|
66
65
|
- lib
|
67
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
67
|
requirements:
|
70
68
|
- - ">="
|
71
69
|
- !ruby/object:Gem::Version
|
72
|
-
hash: 3
|
73
70
|
segments:
|
74
71
|
- 0
|
75
72
|
version: "0"
|
76
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
74
|
requirements:
|
79
75
|
- - ">="
|
80
76
|
- !ruby/object:Gem::Version
|
81
|
-
hash: 3
|
82
77
|
segments:
|
83
78
|
- 0
|
84
79
|
version: "0"
|
85
80
|
requirements: []
|
86
81
|
|
87
82
|
rubyforge_project: simple_audit
|
88
|
-
rubygems_version: 1.3.
|
83
|
+
rubygems_version: 1.3.6
|
89
84
|
signing_key:
|
90
85
|
specification_version: 3
|
91
86
|
summary: Simple auditing solution for ActiveRecord models
|