acts_as_audited_customized 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.2
|
@@ -6,7 +6,6 @@ class AuditModelGenerator < Rails::Generator::NamedBase
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def manifest
|
9
|
-
# puts "*** [AuditModelGenerator.manifest] - File.join(File.dirname(__FILE__), '..', '..', 'lib', 'acts_as_audited') = #{File.join(File.dirname(__FILE__), '..', '..', 'lib', 'acts_as_audited')}"
|
10
9
|
record do |m|
|
11
10
|
m.directory(File.join('app', 'models'))
|
12
11
|
m.template('model.rb', "app/models/audit.rb", :assigns => { :human_model => @human_model })
|
@@ -19,19 +19,39 @@ class Audit < ActiveRecord::Base
|
|
19
19
|
cattr_accessor :audited_class_names
|
20
20
|
self.audited_class_names = Set.new
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
class << self
|
23
|
+
def audited_classes
|
24
|
+
self.audited_class_names.map(&:constantize)
|
25
|
+
end
|
26
|
+
|
27
|
+
# All audits made during the block called will be recorded as made
|
28
|
+
# by +user+. This method is hopefully threadsafe, making it ideal
|
29
|
+
# for background operations that require audit information.
|
30
|
+
def as_user(user, &block)
|
31
|
+
Thread.current[:acts_as_audited_<%= human_model %>] = user
|
32
|
+
yield
|
33
|
+
Thread.current[:acts_as_audited_<%= human_model %>] = nil
|
34
|
+
end
|
25
35
|
|
26
|
-
|
27
|
-
|
28
|
-
# for background operations that require audit information.
|
29
|
-
def self.as_<%= human_model %>(<%= human_model %>, &block)
|
30
|
-
Thread.current[:acts_as_audited_<%= human_model %>] = <%= human_model %>
|
36
|
+
def manual_audit(<%= human_model %>, action, auditable = nil)
|
37
|
+
attribs = { :action => action }
|
31
38
|
|
32
|
-
|
39
|
+
case <%= human_model %>
|
40
|
+
when ActiveRecord::Base
|
41
|
+
attribs[:<%= human_model %>] = <%= human_model %>
|
42
|
+
when String
|
43
|
+
attribs[:username] = <%= human_model %>
|
44
|
+
end
|
45
|
+
|
46
|
+
case auditable
|
47
|
+
when ActiveRecord::Base
|
48
|
+
attribs[:auditable] = auditable
|
49
|
+
when String
|
50
|
+
attribs[:auditable_type] = auditable
|
51
|
+
end
|
33
52
|
|
34
|
-
|
53
|
+
Audit.create attribs
|
54
|
+
end
|
35
55
|
end
|
36
56
|
|
37
57
|
# Allows <%= human_model %> to be set to either a string or an ActiveRecord object
|
@@ -1,15 +1,15 @@
|
|
1
1
|
class <%= class_name %> < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :audits, :force => true do |t|
|
4
|
-
t.
|
5
|
-
t.
|
6
|
-
t.
|
7
|
-
t.
|
8
|
-
t.
|
9
|
-
t.
|
10
|
-
t.
|
11
|
-
t.
|
12
|
-
t.
|
4
|
+
t.integer :auditable_id
|
5
|
+
t.string :auditable_type
|
6
|
+
t.integer :<%= human_model %>_id
|
7
|
+
t.string :<%= human_model %>_type
|
8
|
+
t.string :username
|
9
|
+
t.string :action
|
10
|
+
t.text :changes
|
11
|
+
t.integer :version, :default => 0
|
12
|
+
t.datetime :created_at
|
13
13
|
end
|
14
14
|
|
15
15
|
add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_audited_customized
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 2
|
10
|
+
version: 1.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brandon Keepers
|