change_logger 0.0.1
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/CHANGELOG +0 -0
- data/MIT-LICENSE +0 -0
- data/Manifest +12 -0
- data/README +0 -0
- data/Rakefile +12 -0
- data/change_logger.gemspec +32 -0
- data/lib/app/models/change_log.rb +4 -0
- data/lib/change_logger/acts_as_change_logger.rb +74 -0
- data/lib/change_logger/railtie.rb +7 -0
- data/lib/change_logger/whodunnit.rb +27 -0
- data/lib/change_logger.rb +31 -0
- data/lib/generators/change_logger_generator.rb +8 -0
- data/lib/generators/templates/create_change_logs.rb +16 -0
- data.tar.gz.sig +1 -0
- metadata +111 -0
- metadata.gz.sig +0 -0
data/CHANGELOG
ADDED
File without changes
|
data/MIT-LICENSE
ADDED
File without changes
|
data/Manifest
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
MIT-LICENSE
|
3
|
+
Manifest
|
4
|
+
README
|
5
|
+
Rakefile
|
6
|
+
lib/app/models/change_log.rb
|
7
|
+
lib/change_logger.rb
|
8
|
+
lib/change_logger/acts_as_change_logger.rb
|
9
|
+
lib/change_logger/railtie.rb
|
10
|
+
lib/change_logger/whodunnit.rb
|
11
|
+
lib/generators/change_logger_generator.rb
|
12
|
+
lib/generators/templates/create_change_logs.rb
|
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('change_logger', '0.0.1') do |p|
|
6
|
+
p.description = "A gem for tracking who and what changes"
|
7
|
+
p.url = "http://github.com/danengle/awesome_tables"
|
8
|
+
p.author = "Dan Engle"
|
9
|
+
p.email = "engle.68 @nospam@ gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{change_logger}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Dan Engle"]
|
9
|
+
s.cert_chain = ["/Users/danengle/.ssh/gem-public_cert.pem"]
|
10
|
+
s.date = %q{2010-12-02}
|
11
|
+
s.description = %q{A gem for tracking who and what changes}
|
12
|
+
s.email = %q{engle.68 @nospam@ gmail.com}
|
13
|
+
s.extra_rdoc_files = ["CHANGELOG", "README", "lib/app/models/change_log.rb", "lib/change_logger.rb", "lib/change_logger/acts_as_change_logger.rb", "lib/change_logger/railtie.rb", "lib/change_logger/whodunnit.rb", "lib/generators/change_logger_generator.rb", "lib/generators/templates/create_change_logs.rb"]
|
14
|
+
s.files = ["CHANGELOG", "MIT-LICENSE", "Manifest", "README", "Rakefile", "lib/app/models/change_log.rb", "lib/change_logger.rb", "lib/change_logger/acts_as_change_logger.rb", "lib/change_logger/railtie.rb", "lib/change_logger/whodunnit.rb", "lib/generators/change_logger_generator.rb", "lib/generators/templates/create_change_logs.rb", "change_logger.gemspec"]
|
15
|
+
s.homepage = %q{http://github.com/danengle/awesome_tables}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Change_logger", "--main", "README"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{change_logger}
|
19
|
+
s.rubygems_version = %q{1.3.7}
|
20
|
+
s.signing_key = %q{/Users/danengle/.ssh/gem-private_key.pem}
|
21
|
+
s.summary = %q{A gem for tracking who and what changes}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
28
|
+
else
|
29
|
+
end
|
30
|
+
else
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module ChangeLogger
|
2
|
+
module ActsAsChangeLogger
|
3
|
+
ACTIONS = {
|
4
|
+
:create => 'CREATED',
|
5
|
+
:delete => 'DELETED'
|
6
|
+
}
|
7
|
+
def self.included(base)
|
8
|
+
base.send :extend, ChangeLogger::ActsAsChangeLogger::ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def acts_as_change_logger(options = {})
|
13
|
+
send :include, InstanceMethods
|
14
|
+
cattr_accessor :ignore
|
15
|
+
self.ignore = (options[:ignore] || []).map &:to_s
|
16
|
+
self.ignore.push('created_at', 'updated_at')
|
17
|
+
|
18
|
+
has_many :change_logs, :as => :item, :order => 'change_logs.created_at desc'
|
19
|
+
after_save :record_attribute_updates
|
20
|
+
after_destroy :record_object_destruction
|
21
|
+
self.reflect_on_all_associations(:has_and_belongs_to_many).each do |reflection|
|
22
|
+
if reflection.options.keys.include?(:after_add) || reflection.options.keys.include?(:before_add)
|
23
|
+
logger.warn { "WARNING: change_logger adds after_add and after_remove options to has_and_belongs_to_many relationships. You need to combine your current methods with the record_association_* methods in order for change_logger to work correctly." }
|
24
|
+
end
|
25
|
+
new_options = { :after_add => :record_association_add, :after_remove => :record_association_remove }.merge(reflection.options)
|
26
|
+
has_and_belongs_to_many reflection.name.to_sym, new_options
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module InstanceMethods
|
32
|
+
|
33
|
+
def record_association_add(object)
|
34
|
+
record_change(object.class.to_s, ACTIONS[:create], object.id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def record_association_remove(object)
|
38
|
+
record_change(object.class.to_s, object.id, ACTIONS[:delete])
|
39
|
+
end
|
40
|
+
|
41
|
+
def record_attribute_updates
|
42
|
+
self.changes.delete_if { |k,v| self.class.ignore.include?(k) }.each do |key, value|
|
43
|
+
record_change(key, value[0], value[1])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def record_object_destruction
|
48
|
+
attributes.each do |key, value|
|
49
|
+
record_change(key, old_value(key), ACTIONS[:delete])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def old_value(attribute)
|
56
|
+
if self.new_record?
|
57
|
+
ACTIONS[:create]
|
58
|
+
else
|
59
|
+
send("#{key}_was")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def record_change(attribute_name, old_val, new_val)
|
64
|
+
self.change_logs.create!(
|
65
|
+
:attribute_name => attribute_name,
|
66
|
+
:old_value => old_val,
|
67
|
+
:new_value => new_val,
|
68
|
+
:changed_by_id => whodunnit.id
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
ActiveRecord::Base.send :include, ChangeLogger::ActsAsChangeLogger
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ChangeLogger
|
2
|
+
module Whodunnit
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.before_filter :set_whodunnit
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def whodunnit
|
11
|
+
current_user rescue nil
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def set_whodunnit
|
17
|
+
::ChangeLogger.whodunnit = whodunnit
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
ActionController::Base.send :include, ::ChangeLogger::Whodunnit
|
22
|
+
|
23
|
+
Kernel.module_eval do
|
24
|
+
def whodunnit
|
25
|
+
::ChangeLogger.whodunnit
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
%w{ models }.each do |dir|
|
2
|
+
path = File.join(File.dirname(__FILE__), 'app', dir)
|
3
|
+
$LOAD_PATH << path
|
4
|
+
ActiveSupport::Dependencies.autoload_paths << path
|
5
|
+
ActiveSupport::Dependencies.autoload_once_paths.delete(path)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ChangeLogger
|
9
|
+
def self.whodunnit
|
10
|
+
change_logger_store[:whodunnit]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.whodunnit=(value)
|
14
|
+
change_logger_store[:whodunnit] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# who knows about threads? why is this done this way?
|
20
|
+
def self.change_logger_store
|
21
|
+
Thread.current[:change_logger] ||= {}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'app/models/change_log'
|
26
|
+
require 'change_logger/whodunnit'
|
27
|
+
require 'change_logger/acts_as_change_logger'
|
28
|
+
|
29
|
+
# if defined?(::Rails::Railtie)
|
30
|
+
# require 'change_logger/railtie'
|
31
|
+
# end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class ChangeLoggerGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path("../templates", __FILE__)
|
3
|
+
|
4
|
+
desc "Create the change_logs migration file"
|
5
|
+
def copy_migration
|
6
|
+
copy_file "create_change_logs.rb", "db/migrate/#{Time.now.strftime("%Y%m%d%S")}_create_change_logs.rb"
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateChangeLogs < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :change_logs do |t|
|
4
|
+
t.integer :item_id, :null => false
|
5
|
+
t.string :item_type, :null => false
|
6
|
+
t.string :attribute_name, :old_value, :new_value
|
7
|
+
t.integer :changed_by_id, :null => false
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
add_index :change_logs, [:item_type, :item_id]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :change_logs
|
15
|
+
end
|
16
|
+
end
|
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
i�ox�%�����:�]�ä05�Ǡ��vc�vU.dOūM��ӟ�ӵ�8�g���l�LΩ�A\GIʦ��|
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: change_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dan Engle
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain:
|
16
|
+
- |
|
17
|
+
-----BEGIN CERTIFICATE-----
|
18
|
+
MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhlbmds
|
19
|
+
ZS42ODEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
20
|
+
MB4XDTEwMTAxMTAwNTI1M1oXDTExMTAxMTAwNTI1M1owPzERMA8GA1UEAwwIZW5n
|
21
|
+
bGUuNjgxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
22
|
+
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKf6nWhdrlzcbME1sHRD
|
23
|
+
wbobJ/PfkZZeMmeOI00ij7gtpJ8/GTAHhDSazzNeQUaUJ01+g82QtRyDtXrsosj6
|
24
|
+
vV1HIGAIGESLcOi8vDqnUGZrmY/o3pO7cgYXbHjT9Jn/Uoqt9IXhE97Bf1mYyTvp
|
25
|
+
DznUjccAp+z/8N6xwOEgXqSCfMcfH1zyuurRo13PkJvEKkLAW+PsdA28xovauUXo
|
26
|
+
j2H8+myZLGi5KFeN13UnOo8x0t/McNYkjGaQcVBrIqqX4fle4LNakUfeyJoweXew
|
27
|
+
pAlIjByYtMDQT21fxQLthLayx35nuMXgMWC6+Evzx4U2M7D5GedSxbjZT3uzsHNR
|
28
|
+
pvkCAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4EFgQUt/Ysk6uU3ZrPbcD6kshs
|
29
|
+
ghx0mCYwCwYDVR0PBAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IBAQB9gUK+9jS5asdp
|
30
|
+
cpDlY89APPt9dogKZbt7a8KRJu3qlVfcdW+/naxNOQdRtXspdUlsNdYUGJjJnV0K
|
31
|
+
hZ5TzDCKkH09nhpShLnTbwyB2srwRrMAZWpqvD2f6Muh8H5JB1lxe5RE1v1yZH7d
|
32
|
+
gokx0zsfVuIz2je+OeAz6qmfmiFQnG79vvSaQl6XsDdFsNf51Hdizt7fR1vC7MKr
|
33
|
+
5ZNu0jDZxdAIsmHVdvJK7tMZWq8097ZatwhhE9ReA/ZoMBy4WK7k1G32K2AykCk7
|
34
|
+
in+c1BznEvMTAcQnwGUyalIFnODl9PB5tDyYYUJdPCPxe/YxL9csB3jNDxe6HrZK
|
35
|
+
2MS0NMYj
|
36
|
+
-----END CERTIFICATE-----
|
37
|
+
|
38
|
+
date: 2010-12-02 00:00:00 -06:00
|
39
|
+
default_executable:
|
40
|
+
dependencies: []
|
41
|
+
|
42
|
+
description: A gem for tracking who and what changes
|
43
|
+
email: engle.68 @nospam@ gmail.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files:
|
49
|
+
- CHANGELOG
|
50
|
+
- README
|
51
|
+
- lib/app/models/change_log.rb
|
52
|
+
- lib/change_logger.rb
|
53
|
+
- lib/change_logger/acts_as_change_logger.rb
|
54
|
+
- lib/change_logger/railtie.rb
|
55
|
+
- lib/change_logger/whodunnit.rb
|
56
|
+
- lib/generators/change_logger_generator.rb
|
57
|
+
- lib/generators/templates/create_change_logs.rb
|
58
|
+
files:
|
59
|
+
- CHANGELOG
|
60
|
+
- MIT-LICENSE
|
61
|
+
- Manifest
|
62
|
+
- README
|
63
|
+
- Rakefile
|
64
|
+
- lib/app/models/change_log.rb
|
65
|
+
- lib/change_logger.rb
|
66
|
+
- lib/change_logger/acts_as_change_logger.rb
|
67
|
+
- lib/change_logger/railtie.rb
|
68
|
+
- lib/change_logger/whodunnit.rb
|
69
|
+
- lib/generators/change_logger_generator.rb
|
70
|
+
- lib/generators/templates/create_change_logs.rb
|
71
|
+
- change_logger.gemspec
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://github.com/danengle/awesome_tables
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options:
|
78
|
+
- --line-numbers
|
79
|
+
- --inline-source
|
80
|
+
- --title
|
81
|
+
- Change_logger
|
82
|
+
- --main
|
83
|
+
- README
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
segments:
|
100
|
+
- 1
|
101
|
+
- 2
|
102
|
+
version: "1.2"
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project: change_logger
|
106
|
+
rubygems_version: 1.3.7
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: A gem for tracking who and what changes
|
110
|
+
test_files: []
|
111
|
+
|
metadata.gz.sig
ADDED
Binary file
|