has_audit_trail 0.0.2 → 0.0.3

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/README.md CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install has_audit_trail
20
20
 
21
- Create the migrations:
21
+ Create the migration:
22
22
 
23
23
  $ rails generate has_audit_trail:install
24
24
 
@@ -45,7 +45,7 @@ end
45
45
  ```ruby
46
46
  class Project < ActiveRecord::Base
47
47
  has_many :tasks
48
-
48
+
49
49
  accepts_nested_attributes_for :tasks
50
50
 
51
51
  has_audit_trail(
@@ -3,7 +3,7 @@ require File.expand_path('../lib/has_audit_trail/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Anderson Freitas"]
6
- gem.email = ["me@andersonfreitas.com"]
6
+ gem.email = ["gems@andersonfreitas.com"]
7
7
  gem.description = %q{Simple audit trail for Rails models}
8
8
  gem.summary = gem.description
9
9
  gem.homepage = ""
@@ -17,7 +17,7 @@ module HasAuditTrail
17
17
  class_attribute :audited_collections, :instance_writer => false
18
18
  class_attribute :changed_collections, :instance_writer => false
19
19
 
20
- self.audited_columns = opts[:only] || self.attribute_names.collect { |str| str.to_sym }
20
+ self.audited_columns = opts[:only] || self.column_names.collect { |str| str.to_sym }
21
21
  self.audited_columns -= opts[:except] if opts[:except]
22
22
  self.audited_columns -= [:id, :created_at, :updated_at]
23
23
 
@@ -40,34 +40,34 @@ module HasAuditTrail
40
40
  self.send("after_remove_for_#{attr}") << Proc.new { |owner, record| owner.changed_collections[attr.to_sym][:removed] << record }
41
41
  end
42
42
 
43
- after_create :audit_create
44
- before_update :audit_update
45
- before_destroy :audit_destroy
43
+ after_create :_audit_create
44
+ before_update :_audit_update
45
+ before_destroy :_audit_destroy
46
46
 
47
47
  include HasAuditTrail::AuditTrailInclude::InstanceMethods
48
48
  end
49
49
  end
50
50
  module InstanceMethods
51
- def write_audit(attrs)
51
+ def _write_audit(attrs)
52
52
  attrs.merge!(:object => self.class.model_name, :object_id => self.id)
53
53
  AuditTrail.create!(attrs)
54
54
  end
55
55
 
56
- def audit_create
56
+ def _audit_create
57
57
  self.audited_columns.each do |field|
58
- write_audit(:action => :create, :new_value => self.send(field.to_sym).to_yaml, :property => field.to_sym)
58
+ _write_audit(:action => :create, :new_value => self.send(field.to_sym).to_yaml, :property => field.to_sym)
59
59
  end
60
60
  end
61
61
 
62
- def audit_destroy
63
- write_audit(:action => :destroy)
62
+ def _audit_destroy
63
+ _write_audit(:action => :destroy)
64
64
  end
65
65
 
66
- def audit_update
66
+ def _audit_update
67
67
  if changed?
68
68
  changes.each do |field, change|
69
69
  if self.audited_columns.include? field.to_sym
70
- write_audit(:action => :update, :old_value => change[0].to_yaml, :new_value => change[1].to_yaml, :property => field)
70
+ _write_audit(:action => :update, :old_value => change[0].to_yaml, :new_value => change[1].to_yaml, :property => field)
71
71
  end
72
72
  end
73
73
  end
@@ -78,13 +78,13 @@ module HasAuditTrail
78
78
  if changed_collections[attr][:added].size > 0
79
79
  old = self.send(attr) - changed_collections[attr][:added]
80
80
 
81
- write_audit(:action => :update, :old_value => old.collect { |x| x.name }, :new_value => self.send(attr).collect {|x|x.name}, :property => attr)
81
+ _write_audit(:action => :update, :old_value => old.collect { |x| x.name }, :new_value => self.send(attr).collect {|x|x.name}, :property => attr)
82
82
  changed_collections[attr][:added] = []
83
83
  end
84
84
  if changed_collections[attr][:removed].size > 0
85
85
  old = self.send(attr) + changed_collections[attr][:removed]
86
86
 
87
- write_audit(:action => :update, :old_value => old.collect { |x| x.name }, :new_value => self.send(attr).collect {|x|x.name}, :property => attr)
87
+ _write_audit(:action => :update, :old_value => old.collect { |x| x.name }, :new_value => self.send(attr).collect {|x|x.name}, :property => attr)
88
88
  changed_collections[attr][:removed] = []
89
89
  end
90
90
  end
@@ -97,7 +97,7 @@ module HasAuditTrail
97
97
  if c.changed?
98
98
  c.changes.each do |field, change|
99
99
  if change[0].to_s != change[1].to_s
100
- write_audit(:action => :update, :old_value => change[0].to_yaml, :new_value => change[1].to_yaml, :property => procs[:label].call(c))
100
+ _write_audit(:action => :update, :old_value => change[0].to_yaml, :new_value => change[1].to_yaml, :property => procs[:label].call(c))
101
101
  end
102
102
  end
103
103
  end
@@ -1,3 +1,3 @@
1
1
  module HasAuditTrail
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_audit_trail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-25 00:00:00.000000000 Z
12
+ date: 2012-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '3.0'
110
110
  description: Simple audit trail for Rails models
111
111
  email:
112
- - me@andersonfreitas.com
112
+ - gems@andersonfreitas.com
113
113
  executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []