simple_audit 0.0.1 → 0.0.2

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.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 [name of plugin creator]
1
+ Copyright (c) 2010 [Gabriel Târnovan]
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -1,18 +1,122 @@
1
- # SimpleAudit
1
+ # simple_audit
2
2
 
3
+ Simple auditing solution for ActiveRecord models. Provides an easy way of creating audit logs for complex model associations.
4
+ Instead of storing audits for all data aggregated by the audited model, you can specify a serializable representation of the model.
5
+
6
+ * a helper method is provided to easily display the audit log
7
+ * the Audit object provides a #delta method which computs the differences between two audits
3
8
 
4
- Simple auditing solution for ActiveRecord models.
9
+ In a nutshell:
5
10
 
11
+ class Booking < ActiveRecord::Base
12
+ simple_audit
13
+
14
+ # data to be audited
15
+ def audit_changes
16
+ {
17
+ :price => self.price,
18
+ :period => self.period,
19
+ ...
20
+ }
21
+ end
22
+ end
23
+
24
+ # in your view
25
+ <%= render_audits(@booking) %>
6
26
 
7
- # Installation
27
+ # Why ?
28
+
29
+ simple_audit is intended as a straightforward auditing solution for complex model associations.
30
+ In a normalized data structure (which is usually the case when using SQL), a core business model will aggregate data from several associated entities.
31
+ More often than not in such cases, only the core model is of interest from an auditing point of view.
32
+
33
+ So instead of auditing every entity sepparately, with simple_audit you decide for each audited model what data needs to be audited.
34
+ This data will be serialized on every model update and the available helper methods will render a clear audit trail.
35
+
36
+ ![Screenshot of helper result](http://github.com/gtarnovan/simple_audit/raw/master/screenshot.png)s
37
+
38
+ # Installation & Configuration
39
+
40
+ ## As a gem
41
+
42
+ gem install simple_audit
43
+
44
+ and require it
45
+
46
+ config.gem 'simple_audit'
8
47
 
9
48
  ## As a plugin
10
- ./script/plugin install http://github.com/gtarnovan/simple_audit
49
+
50
+ ./script/plugin install http://github.com/gtarnovan/simple_audit
51
+
52
+ ## Database
53
+
54
+ Generate and run migration
55
+
56
+ ./script/generate simple_audit_migration create_audits
57
+ rake db:migrate
58
+
59
+ # Usage
60
+
61
+ Audit ActiveRecord models. Somewhere in your (backend) views show the audit logs.
62
+
63
+ # in your model
64
+ # app/models/booking.rb
65
+
66
+ class Booking < ActiveRecord::Base
67
+ simple_audit
68
+ ...
69
+ end
70
+
71
+ # in your view
72
+ # app/views/bookings/booking.html.erb
73
+
74
+ ...
75
+ <%= render_audits(@booking) %>
76
+ ...
77
+
78
+ # Assumptions and limitations
79
+
80
+ * Your user model is called User and the current user User.current
81
+ See [sentient_user](http://github.com/bokmann/sentient_user) for more information.
82
+
83
+ * You have to write your own tests (fow now)
84
+
85
+
86
+
87
+ ## Customize auditing
88
+
89
+ By default after each save, all model's attributes are saved in the audits table.
90
+ You can customize the data which is saved by overriding the audit_changes method. All relevant data for the audited model should be included here.
11
91
 
12
- # Example
92
+ # app/models/booking.rb
93
+
94
+ class Booking < ActiveRecord::Base
95
+ simple_audit
96
+
97
+ def audit_changes
98
+ {
99
+ :state => self.state,
100
+ :price => self.price.format,
101
+ :period => self.period.to_s,
102
+ :housing_units => housing_units.collect(&:name).join('; '),
103
+ ...
104
+ }
105
+ end
106
+ ...
107
+ end
108
+
109
+ You can also customize the attribute of the User model which will be stored in the audit.
13
110
 
111
+ # default is :name
112
+ simple_audit :username_method => :email
113
+
114
+ ## Rendering audit
14
115
 
15
- Example goes here.
116
+ A helper method for displaying a list of audits is provided. It will render a decorated list of the provided audits;
117
+ only the differences between revisions will be shown, thus making the audit information easily readable.
16
118
 
119
+ ![Screenshot of helper result](http://github.com/gtarnovan/simple_audit/raw/master/screenshot.png)
120
+
17
121
 
18
- Copyright (c) 2010 [name of plugin creator], released under the MIT license
122
+ Copyright (c) 2010 [Gabriel Târnovan, Cubus Arts](http://cubus.ro "Cubus Arts"), released under the MIT license
data/Rakefile CHANGED
@@ -43,7 +43,7 @@ begin
43
43
  gemspec.email = "gabriel.tarnovan@cubus.ro"
44
44
  gemspec.homepage = "http://github.com/gtarnovan/simple_audit"
45
45
  gemspec.authors = ["Gabriel Tarnovan"]
46
- gemspec.version = "0.0.1"
46
+ gemspec.version = "0.0.2"
47
47
  gemspec.files = gem_files.to_a
48
48
 
49
49
  gemspec.rubyforge_project = 'simple_audit'
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+ * migration generator
2
+ * customizable method for getting the current user
3
+ * tests
@@ -1,7 +1,8 @@
1
1
  module SimpleAuditHelper
2
2
 
3
- def render_audits(audits)
4
- audits = audits.dup.sort{|a, b| b.created_at <=> a.created_at}
3
+ def render_audits(audited_model)
4
+ return '' unless audited_model.respond_to?(:audits)
5
+ audits = (audited_model.audits || []).dup.sort{|a,b| b.created_at <=> a.created_at}
5
6
  res = ''
6
7
  audits.each_with_index do |audit, index|
7
8
  older_audit = audits[index + 1]
data/screenshot.png ADDED
Binary file
data/simple_audit.gemspec CHANGED
@@ -5,23 +5,27 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{simple_audit}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
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"]
12
- s.date = %q{2010-06-02}
12
+ s.date = %q{2010-06-04}
13
13
  s.email = %q{gabriel.tarnovan@cubus.ro}
14
14
  s.extra_rdoc_files = [
15
- "README.markdown"
15
+ "LICENSE",
16
+ "README.markdown",
17
+ "TODO"
16
18
  ]
17
19
  s.files = [
18
- "MIT-LICENSE",
20
+ "LICENSE",
19
21
  "README.markdown",
20
22
  "Rakefile",
23
+ "TODO",
21
24
  "lib/app/helpers/simple_audit_helper.rb",
22
25
  "lib/app/models/audit.rb",
23
26
  "lib/simple_audit.rb",
24
27
  "rails/init.rb",
28
+ "screenshot.png",
25
29
  "simple_audit.gemspec",
26
30
  "tasks/simple_audit_tasks.rake",
27
31
  "test/simple_audit_test.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gabriel Tarnovan
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-02 00:00:00 +03:00
17
+ date: 2010-06-04 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -25,15 +25,19 @@ executables: []
25
25
  extensions: []
26
26
 
27
27
  extra_rdoc_files:
28
+ - LICENSE
28
29
  - README.markdown
30
+ - TODO
29
31
  files:
30
- - MIT-LICENSE
32
+ - LICENSE
31
33
  - README.markdown
32
34
  - Rakefile
35
+ - TODO
33
36
  - lib/app/helpers/simple_audit_helper.rb
34
37
  - lib/app/models/audit.rb
35
38
  - lib/simple_audit.rb
36
39
  - rails/init.rb
40
+ - screenshot.png
37
41
  - simple_audit.gemspec
38
42
  - tasks/simple_audit_tasks.rake
39
43
  - test/simple_audit_test.rb