change_logger 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -1,7 +1,7 @@
1
1
  CHANGELOG
2
2
  MIT-LICENSE
3
3
  Manifest
4
- README
4
+ README.rdoc
5
5
  Rakefile
6
6
  cucumber.yml.bac
7
7
  features/log_changes.feature
data/README.rdoc ADDED
@@ -0,0 +1,29 @@
1
+ = change_logger
2
+
3
+ change_logger is based off of https://github.com/airblade/paper_trail. Instead of storing the whole updated object in a text column, it creates a record for each changed value. Not sure if it's a better way of tracking changes, but it's how I wanted the changes stored.
4
+
5
+ == Download
6
+
7
+ Github: http://github.com/danengle/change_logger
8
+
9
+ Gem:
10
+ gem install change_logger
11
+
12
+ == Usage
13
+
14
+ Run the generator to create the migration
15
+ rails g change_logger
16
+ rake db:migrate
17
+
18
+ In any model that you want to track changes, add acts_as_change_logger below all of the association declarations so that it can properly hook into any has_and_belongs_to_many associations. Use the ignore option to not save changes for certain attributes.
19
+
20
+ class User < ActiveRecord::Base
21
+ has_many :things
22
+ has_and_belongs_to_many :permissions
23
+
24
+ acts_as_change_logger :ignore => [:crypted_password, :password_salt]
25
+ end
26
+
27
+ == Notes on tests
28
+
29
+ There are cucumber stories that pass, but I don't seem to be using them quite how they are supposed to be. It is testable completely outside of the rails environment, but seems to akwardly incorporate the parts needed to make suitable tests. If you're able to give me some pointers on how better to setup the tests, please do.
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake'
4
4
  require 'echoe'
5
5
  require 'env'
6
6
 
7
- Echoe.new('change_logger', '0.0.3') do |p|
7
+ Echoe.new('change_logger', '0.0.4') do |p|
8
8
  p.description = "A gem for tracking what changes and who did it"
9
9
  p.url = "http://github.com/danengle/awesome_tables"
10
10
  p.author = "Dan Engle"
@@ -2,26 +2,23 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{change_logger}
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Dan Engle"]
9
- s.cert_chain = ["/Users/danengle/.ssh/gem-public_cert.pem"]
10
- s.date = %q{2010-12-05}
9
+ s.date = %q{2011-03-09}
11
10
  s.description = %q{A gem for tracking what changes and who did it}
12
11
  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", "cucumber.yml.bac", "features/log_changes.feature", "features/step_definitions/log_changes_steps.rb", "features/support/env.rb", "features/support/hooks.rb", "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", "spec/factories.rb", "spec/migrate/20101201_init_test_db.rb", "spec/models/permission.rb", "spec/models/user.rb", "change_logger.gemspec"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "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"]
13
+ s.files = ["CHANGELOG", "MIT-LICENSE", "Manifest", "README.rdoc", "Rakefile", "cucumber.yml.bac", "features/log_changes.feature", "features/step_definitions/log_changes_steps.rb", "features/support/env.rb", "features/support/hooks.rb", "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", "spec/factories.rb", "spec/migrate/20101201_init_test_db.rb", "spec/models/permission.rb", "spec/models/user.rb", "change_logger.gemspec"]
15
14
  s.homepage = %q{http://github.com/danengle/awesome_tables}
16
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Change_logger", "--main", "README"]
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Change_logger", "--main", "README.rdoc"]
17
16
  s.require_paths = ["lib"]
18
17
  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}
18
+ s.rubygems_version = %q{1.5.0}
21
19
  s.summary = %q{A gem for tracking what changes and who did it}
22
20
 
23
21
  if s.respond_to? :specification_version then
24
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
22
  s.specification_version = 3
26
23
 
27
24
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -2,6 +2,7 @@ module ChangeLogger
2
2
  module ActsAsChangeLogger
3
3
  ACTIONS = {
4
4
  :create => 'CREATED',
5
+ :update => 'UPDATED',
5
6
  :delete => 'DELETED'
6
7
  }
7
8
  def self.included(base)
@@ -11,12 +12,18 @@ module ChangeLogger
11
12
  module ClassMethods
12
13
  def acts_as_change_logger(options = {})
13
14
  send :include, InstanceMethods
14
- cattr_accessor :ignore
15
+
16
+ cattr_accessor :ignore, :track_templates
15
17
  self.ignore = (options[:ignore] || []).map &:to_s
16
- self.ignore.push('id', 'created_at', 'updated_at')
18
+ self.ignore.push('id', 'revision', 'created_at', 'updated_at')
19
+ self.track_templates = (options[:track_templates] || []).map &:to_s
20
+
21
+ attr_accessor :template_changed
22
+ after_update :record_template_change
17
23
 
18
24
  has_many :change_logs, :as => :item, :order => 'change_logs.created_at desc'
19
25
  after_create :record_object_creation
26
+ before_update :increment_revision
20
27
  after_update :record_attribute_updates
21
28
  before_destroy :record_object_destruction
22
29
  self.reflect_on_all_associations(:has_and_belongs_to_many).each do |reflection|
@@ -31,12 +38,35 @@ module ChangeLogger
31
38
 
32
39
  module InstanceMethods
33
40
 
41
+ def increment_revision
42
+ self.increment(:revision) if self.respond_to?(:revision)
43
+ end
44
+
45
+ def record_template_change
46
+ self.template_changed = {} if self.template_changed.nil?
47
+ if self.template_changed.values.include?(true)
48
+ self.template_changed.keys.each do |relation|
49
+ record_change("#{relation}_template", ACTIONS[:update], self.send(relation).to_yaml)
50
+ end
51
+ end
52
+ end
53
+
34
54
  def record_association_add(object)
35
- record_change(object.class.to_s, ACTIONS[:create], object.id) if self.persisted?
55
+ if self.class.track_templates.include?(object.class.to_s.tableize)
56
+ self.template_changed = {} if self.template_changed.nil?
57
+ self.template_changed[object.class.to_s.tableize.to_sym] = true
58
+ else
59
+ record_change(object.class.to_s, ACTIONS[:create], object.id) if self.persisted?
60
+ end
36
61
  end
37
62
 
38
63
  def record_association_remove(object)
39
- record_change(object.class.to_s, object.id, ACTIONS[:delete]) if self.persisted?
64
+ if self.class.track_templates.include?(object.class.to_s.tableize)
65
+ self.template_changed = {} if self.template_changed.nil?
66
+ self.template_changed[object.class.to_s.tableize.to_sym] = true
67
+ else
68
+ record_change(object.class.to_s, object.id, ACTIONS[:delete]) if self.persisted?
69
+ end
40
70
  end
41
71
 
42
72
  def record_object_creation
@@ -64,13 +94,16 @@ module ChangeLogger
64
94
  private
65
95
 
66
96
  def record_change(attribute_name, old_val, new_val)
67
- self.change_logs.create(
97
+ change_log = self.change_logs.new(
68
98
  :attribute_name => attribute_name,
69
99
  :old_value => old_val,
70
100
  :new_value => new_val,
71
101
  :changed_by => whodunnit
72
102
  )
103
+ change_log.revision = self.revision if self.respond_to?(:revision)
104
+ change_log.save
73
105
  end
106
+
74
107
  end
75
108
  end
76
109
  end
@@ -5,16 +5,10 @@ module ChangeLogger
5
5
  base.before_filter :set_whodunnit
6
6
  end
7
7
 
8
- protected
9
-
10
- def whodunnit
11
- current_user rescue nil
12
- end
13
-
14
8
  private
15
9
 
16
10
  def set_whodunnit
17
- ::ChangeLogger.whodunnit = whodunnit
11
+ ::ChangeLogger.whodunnit = current_user.login rescue nil
18
12
  end
19
13
  end
20
14
  end
@@ -4,7 +4,7 @@ class CreateChangeLogs < ActiveRecord::Migration
4
4
  t.integer :item_id, :null => false
5
5
  t.string :item_type, :null => false
6
6
  t.string :attribute_name, :old_value, :new_value
7
- t.string :changed_by, :null => false
7
+ t.string :changed_by
8
8
  t.datetime :created_at
9
9
  end
10
10
  add_index :change_logs, [:item_type, :item_id]
metadata CHANGED
@@ -1,41 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: change_logger
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 3
9
- version: 0.0.3
4
+ prerelease:
5
+ version: 0.0.4
10
6
  platform: ruby
11
7
  authors:
12
8
  - Dan Engle
13
9
  autorequire:
14
10
  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-----
11
+ cert_chain: []
37
12
 
38
- date: 2010-12-05 00:00:00 -06:00
13
+ date: 2011-03-09 00:00:00 -06:00
39
14
  default_executable:
40
15
  dependencies: []
41
16
 
@@ -47,7 +22,7 @@ extensions: []
47
22
 
48
23
  extra_rdoc_files:
49
24
  - CHANGELOG
50
- - README
25
+ - README.rdoc
51
26
  - lib/app/models/change_log.rb
52
27
  - lib/change_logger.rb
53
28
  - lib/change_logger/acts_as_change_logger.rb
@@ -59,7 +34,7 @@ files:
59
34
  - CHANGELOG
60
35
  - MIT-LICENSE
61
36
  - Manifest
62
- - README
37
+ - README.rdoc
63
38
  - Rakefile
64
39
  - cucumber.yml.bac
65
40
  - features/log_changes.feature
@@ -89,7 +64,7 @@ rdoc_options:
89
64
  - --title
90
65
  - Change_logger
91
66
  - --main
92
- - README
67
+ - README.rdoc
93
68
  require_paths:
94
69
  - lib
95
70
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -97,22 +72,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
72
  requirements:
98
73
  - - ">="
99
74
  - !ruby/object:Gem::Version
100
- segments:
101
- - 0
102
75
  version: "0"
103
76
  required_rubygems_version: !ruby/object:Gem::Requirement
104
77
  none: false
105
78
  requirements:
106
79
  - - ">="
107
80
  - !ruby/object:Gem::Version
108
- segments:
109
- - 1
110
- - 2
111
81
  version: "1.2"
112
82
  requirements: []
113
83
 
114
84
  rubyforge_project: change_logger
115
- rubygems_version: 1.3.7
85
+ rubygems_version: 1.5.0
116
86
  signing_key:
117
87
  specification_version: 3
118
88
  summary: A gem for tracking what changes and who did it
data/README DELETED
File without changes
data.tar.gz.sig DELETED
@@ -1 +0,0 @@
1
- �Ы���{V�?��@��,�õݭ��8���kD[!�����h7cy`�&�;���/E��%�Fc�r9�̕)���p� Ls��P{�H_=���,re�:A����3y|�I��z�)|@��c&�?0����%$B���Do��04�8\D�֪ �k5�ly˄aY1�Hx(.[y\�#ɔ�j�jT^cp-�TF��\R� W��:��Ys#�r ��y�����=yG� ѵb |xt+).T��E@.��my��uR
metadata.gz.sig DELETED
Binary file