acts_as_audited_customized 1.2.1 → 1.2.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
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
- def self.audited_classes
23
- self.audited_class_names.map(&:constantize)
24
- end
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
- # All audits made during the block called will be recorded as made
27
- # by +<%= human_model %>+. This method is hopefully threadsafe, making it ideal
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
- yield
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
- Thread.current[:acts_as_audited_<%= human_model %>] = nil
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
@@ -6,7 +6,6 @@ class AuditedMigrationGenerator < Rails::Generator::NamedBase
6
6
 
7
7
  def manifest
8
8
  record do |m|
9
- m.directory(File.join('db', 'migrate'))
10
9
  m.migration_template 'migration.rb', 'db/migrate', :assigns => { :human_model => @human_model }
11
10
  end
12
11
  end
@@ -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.column :auditable_id, :integer
5
- t.column :auditable_type, :string
6
- t.column :<%= human_model %>_id, :integer
7
- t.column :<%= human_model %>_type, :string
8
- t.column :username, :string
9
- t.column :action, :string
10
- t.column :changes, :text
11
- t.column :version, :integer, :default => 0
12
- t.column :created_at, :datetime
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 1
10
- version: 1.2.1
9
+ - 2
10
+ version: 1.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brandon Keepers