notifiably_audited-activerecord 0.0.7
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.
- checksums.yaml +15 -0
- data/LICENSE +19 -0
- data/lib/audited-activerecord.rb +2 -0
- data/lib/audited/adapters/active_record.rb +15 -0
- data/lib/audited/adapters/active_record/audit.rb +69 -0
- data/lib/generators/audited/install_generator.rb +28 -0
- data/lib/generators/audited/templates/add_association_to_audits.rb +11 -0
- data/lib/generators/audited/templates/add_comment_to_audits.rb +9 -0
- data/lib/generators/audited/templates/add_remote_address_to_audits.rb +10 -0
- data/lib/generators/audited/templates/install.rb +35 -0
- data/lib/generators/audited/templates/rename_association_to_associated.rb +23 -0
- data/lib/generators/audited/templates/rename_changes_to_audited_changes.rb +9 -0
- data/lib/generators/audited/templates/rename_parent_to_association.rb +11 -0
- data/lib/generators/audited/upgrade_generator.rb +63 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NWZlNGJiMTZmMDM5ZGIzOTUwMzM0NjgxNzY3Yzg2MmI5ODczNWFlZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDRkNzM5YzNjODAyZGRmNjljZTM3OTBjYmEzODc0MGFjNTQ5M2RlZg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjIxNTY1MmE5MmIzODA1OTMxYzc4MWMzNDNjNGNmOTc5MzE3MWZlNDU1ODgw
|
10
|
+
NmQ2N2U0OTczZDMwNjQyZThhY2JhYWZjODQxMDQ1NjkwOGM1ZGYzZDQ0Mzdi
|
11
|
+
OTY0YzdkNjM4M2NhMjUxNGM1NGQ0NmIyODA5MDhjMDMwMzJmMTg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDkxZTI3ZDA5NTdjNjM2ZWVlOGIxNjZhYjBiNjJjNWQyNTYyMDBiNmQxNDMz
|
14
|
+
ODUzZjI5YzI4OWYyNzAzNDNhZjg5MmVhZTRkMGNiMWUwZDBkMWZhZmFkMTY0
|
15
|
+
MDUwOTU5MjU4YWZjOTQyN2IxNTVkOWYxMDk3OTEwYmZiZjgyODU=
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright © 2010 Brandon Keepers - Collective Idea
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'audited/auditor'
|
3
|
+
require 'audited/adapters/active_record/audit'
|
4
|
+
|
5
|
+
module Audited::Auditor::ClassMethods
|
6
|
+
def default_ignored_attributes
|
7
|
+
[self.primary_key, inheritance_column]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
::ActiveRecord::Base.send :include, Audited::Auditor
|
12
|
+
|
13
|
+
Audited.audit_class = Audited::Adapters::ActiveRecord::Audit
|
14
|
+
|
15
|
+
require 'audited/sweeper'
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'audited/audit'
|
3
|
+
|
4
|
+
module Audited
|
5
|
+
module Adapters
|
6
|
+
module ActiveRecord
|
7
|
+
# Audit saves the changes to ActiveRecord models. It has the following attributes:
|
8
|
+
#
|
9
|
+
# * <tt>auditable</tt>: the ActiveRecord model that was changed
|
10
|
+
# * <tt>user</tt>: the user that performed the change; a string or an ActiveRecord model
|
11
|
+
# * <tt>action</tt>: one of create, update, or delete
|
12
|
+
# * <tt>audited_changes</tt>: a serialized hash of all the changes
|
13
|
+
# * <tt>comment</tt>: a comment set with the audit
|
14
|
+
# * <tt>created_at</tt>: Time that the change was performed
|
15
|
+
#
|
16
|
+
class Audit < ::ActiveRecord::Base
|
17
|
+
include Audited::Audit
|
18
|
+
|
19
|
+
|
20
|
+
serialize :audited_changes
|
21
|
+
|
22
|
+
default_scope order(:version)
|
23
|
+
scope :descending, reorder("version DESC")
|
24
|
+
scope :creates, :conditions => {:action => 'create'}
|
25
|
+
scope :updates, :conditions => {:action => 'update'}
|
26
|
+
scope :destroys, :conditions => {:action => 'destroy'}
|
27
|
+
|
28
|
+
scope :up_until, lambda {|date_or_time| where("created_at <= ?", date_or_time) }
|
29
|
+
scope :from_version, lambda {|version| where(['version >= ?', version]) }
|
30
|
+
scope :to_version, lambda {|version| where(['version <= ?', version]) }
|
31
|
+
|
32
|
+
# Return all audits older than the current one.
|
33
|
+
def ancestors
|
34
|
+
self.class.where(['auditable_id = ? and auditable_type = ? and version <= ?',
|
35
|
+
auditable_id, auditable_type, version])
|
36
|
+
end
|
37
|
+
|
38
|
+
# Allows user to be set to either a string or an ActiveRecord object
|
39
|
+
# @private
|
40
|
+
def user_as_string=(user)
|
41
|
+
# reset both either way
|
42
|
+
self.user_as_model = self.username = nil
|
43
|
+
user.is_a?(::ActiveRecord::Base) ?
|
44
|
+
self.user_as_model = user :
|
45
|
+
self.username = user
|
46
|
+
end
|
47
|
+
alias_method :user_as_model=, :user=
|
48
|
+
alias_method :user=, :user_as_string=
|
49
|
+
|
50
|
+
# @private
|
51
|
+
def user_as_string
|
52
|
+
self.user_as_model || self.username
|
53
|
+
end
|
54
|
+
alias_method :user_as_model, :user
|
55
|
+
alias_method :user, :user_as_string
|
56
|
+
|
57
|
+
private
|
58
|
+
def set_version_number
|
59
|
+
max = self.class.maximum(:version,
|
60
|
+
:conditions => {
|
61
|
+
:auditable_id => auditable_id,
|
62
|
+
:auditable_type => auditable_type
|
63
|
+
}) || 0
|
64
|
+
self.version = max + 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'active_record'
|
4
|
+
require 'rails/generators/active_record'
|
5
|
+
|
6
|
+
module Audited
|
7
|
+
module Generators
|
8
|
+
class InstallGenerator < Rails::Generators::Base
|
9
|
+
include Rails::Generators::Migration
|
10
|
+
|
11
|
+
source_root File.expand_path("../templates", __FILE__)
|
12
|
+
|
13
|
+
# Implement the required interface for Rails::Generators::Migration.
|
14
|
+
def self.next_migration_number(dirname) #:nodoc:
|
15
|
+
next_migration_number = current_migration_number(dirname) + 1
|
16
|
+
if ActiveRecord::Base.timestamped_migrations
|
17
|
+
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
18
|
+
else
|
19
|
+
"%.3d" % next_migration_number
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy_migration
|
24
|
+
migration_template 'install.rb', 'db/migrate/install_audited.rb'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :audits, :association_id, :integer
|
4
|
+
add_column :audits, :association_type, :string
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
remove_column :audits, :association_type
|
9
|
+
remove_column :audits, :association_id
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :audits, :force => true do |t|
|
4
|
+
t.column :auditable_id, :integer
|
5
|
+
t.column :auditable_type, :string
|
6
|
+
t.column :associated_id, :integer
|
7
|
+
t.column :associated_type, :string
|
8
|
+
t.column :user_id, :integer
|
9
|
+
t.column :user_type, :string
|
10
|
+
t.column :username, :string
|
11
|
+
t.column :action, :string
|
12
|
+
t.column :audited_changes, :text
|
13
|
+
t.column :version, :integer, :default => 0
|
14
|
+
t.column :comment, :string
|
15
|
+
t.column :remote_address, :string
|
16
|
+
# added by senthil
|
17
|
+
#========
|
18
|
+
t.column :meta, :string
|
19
|
+
t.column :receiver_id, :integer
|
20
|
+
t.column :checked, :boolean
|
21
|
+
t.column :title, :string
|
22
|
+
#========
|
23
|
+
t.column :created_at, :datetime
|
24
|
+
end
|
25
|
+
|
26
|
+
add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index'
|
27
|
+
add_index :audits, [:associated_id, :associated_type], :name => 'associated_index'
|
28
|
+
add_index :audits, [:user_id, :user_type], :name => 'user_index'
|
29
|
+
add_index :audits, :created_at
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.down
|
33
|
+
drop_table :audits
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
if index_exists? :audits, [:association_id, :association_type], :name => 'association_index'
|
4
|
+
remove_index :audits, :name => 'association_index'
|
5
|
+
end
|
6
|
+
|
7
|
+
rename_column :audits, :association_id, :associated_id
|
8
|
+
rename_column :audits, :association_type, :associated_type
|
9
|
+
|
10
|
+
add_index :audits, [:associated_id, :associated_type], :name => 'associated_index'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
if index_exists? :audits, [:associated_id, :associated_type], :name => 'associated_index'
|
15
|
+
remove_index :audits, :name => 'associated_index'
|
16
|
+
end
|
17
|
+
|
18
|
+
rename_column :audits, :associated_type, :association_type
|
19
|
+
rename_column :audits, :associated_id, :association_id
|
20
|
+
|
21
|
+
add_index :audits, [:association_id, :association_type], :name => 'association_index'
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
rename_column :audits, :auditable_parent_id, :association_id
|
4
|
+
rename_column :audits, :auditable_parent_type, :association_type
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
rename_column :audits, :association_type, :auditable_parent_type
|
9
|
+
rename_column :audits, :association_id, :auditable_parent_id
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'active_record'
|
4
|
+
require 'rails/generators/active_record'
|
5
|
+
|
6
|
+
module Audited
|
7
|
+
module Generators
|
8
|
+
class UpgradeGenerator < Rails::Generators::Base
|
9
|
+
include Rails::Generators::Migration
|
10
|
+
|
11
|
+
source_root File.expand_path("../templates", __FILE__)
|
12
|
+
|
13
|
+
# Implement the required interface for Rails::Generators::Migration.
|
14
|
+
def self.next_migration_number(dirname) #:nodoc:
|
15
|
+
next_migration_number = current_migration_number(dirname) + 1
|
16
|
+
if ActiveRecord::Base.timestamped_migrations
|
17
|
+
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
18
|
+
else
|
19
|
+
"%.3d" % next_migration_number
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy_templates
|
24
|
+
migrations_to_be_applied do |m|
|
25
|
+
migration_template "#{m}.rb", "db/migrate/#{m}.rb"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def migrations_to_be_applied
|
32
|
+
Audited::Adapters::ActiveRecord::Audit.reset_column_information
|
33
|
+
columns = Audited::Adapters::ActiveRecord::Audit.columns.map(&:name)
|
34
|
+
|
35
|
+
unless columns.include?( 'comment' )
|
36
|
+
yield :add_comment_to_audits
|
37
|
+
end
|
38
|
+
|
39
|
+
if columns.include?( 'changes' )
|
40
|
+
yield :rename_changes_to_audited_changes
|
41
|
+
end
|
42
|
+
|
43
|
+
unless columns.include?( 'remote_address' )
|
44
|
+
yield :add_remote_address_to_audits
|
45
|
+
end
|
46
|
+
|
47
|
+
unless columns.include?( 'association_id' )
|
48
|
+
if columns.include?('auditable_parent_id')
|
49
|
+
yield :rename_parent_to_association
|
50
|
+
else
|
51
|
+
unless columns.include?( 'associated_id' )
|
52
|
+
yield :add_association_to_audits
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if columns.include?( 'association_id' )
|
58
|
+
yield :rename_association_to_associated
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: notifiably_audited-activerecord
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- senthil kumar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: notifiably_audited
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
description: Log all changes to your ActiveRecord models
|
42
|
+
email: senthilkumar.hce@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- LICENSE
|
48
|
+
- lib/audited-activerecord.rb
|
49
|
+
- lib/audited/adapters/active_record.rb
|
50
|
+
- lib/audited/adapters/active_record/audit.rb
|
51
|
+
- lib/generators/audited/install_generator.rb
|
52
|
+
- lib/generators/audited/templates/add_association_to_audits.rb
|
53
|
+
- lib/generators/audited/templates/add_comment_to_audits.rb
|
54
|
+
- lib/generators/audited/templates/add_remote_address_to_audits.rb
|
55
|
+
- lib/generators/audited/templates/install.rb
|
56
|
+
- lib/generators/audited/templates/rename_association_to_associated.rb
|
57
|
+
- lib/generators/audited/templates/rename_changes_to_audited_changes.rb
|
58
|
+
- lib/generators/audited/templates/rename_parent_to_association.rb
|
59
|
+
- lib/generators/audited/upgrade_generator.rb
|
60
|
+
homepage: ''
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.2
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: ''
|
84
|
+
test_files: []
|
85
|
+
has_rdoc:
|