cia 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cia (0.4.3)
4
+ cia (0.4.4)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/Readme.md CHANGED
@@ -74,9 +74,20 @@ class User < ActiveRecord::Base
74
74
  include CIA::Auditable
75
75
  audited_attributes :email, :crypted_password, :callback => :after_commit
76
76
  end
77
+
78
+ # passing arbitrary attributes into the .audit method
79
+ CIA.non_recordable_attributes = [:my_pretty_audit_property]
80
+ CIA.audit(:actor => current_user, :my_pretty_audit_property => "12345") do
81
+ ...
82
+ end
83
+
84
+
77
85
  ```
78
86
 
79
87
 
88
+ # TODO
89
+ - reuse AR3+ previous_changes in a nice way
90
+
80
91
  Author
81
92
  ======
82
93
  [Michael Grosser](http://grosser.it)<br/>
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/cia
3
3
  specs:
4
- cia (0.4.2)
4
+ cia (0.4.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/cia
3
3
  specs:
4
- cia (0.4.2)
4
+ cia (0.4.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/lib/cia.rb CHANGED
@@ -8,6 +8,7 @@ module CIA
8
8
 
9
9
  class << self
10
10
  attr_accessor :exception_handler
11
+ attr_accessor :non_recordable_attributes
11
12
  end
12
13
 
13
14
  def self.audit(options = {})
@@ -36,12 +37,15 @@ module CIA
36
37
  return if options and options[:if] and not source.send(options[:if])
37
38
  return if options and options[:unless] and source.send(options[:unless])
38
39
 
39
- changes = (source.stored_cia_changes || source.cia_changes).slice(*source.class.audited_attributes)
40
+ changes = (source.cia_previous_changes || source.cia_changes).slice(*source.class.audited_attributes)
40
41
  message = source.audit_message if source.respond_to?(:audit_message)
41
42
 
42
43
  return if not message and changes.empty? and action.to_s == "update"
43
44
 
44
- event = CIA::Event.new(current_transaction.merge(
45
+ transaction_attributes = current_transaction.dup
46
+ transaction_attributes.reject! { |k, v| non_recordable_attributes.include?(k) } if non_recordable_attributes
47
+
48
+ event = CIA::Event.new(transaction_attributes.merge(
45
49
  :action => action.to_s,
46
50
  :source => source,
47
51
  :message => message
data/lib/cia/auditable.rb CHANGED
@@ -9,11 +9,11 @@ module CIA
9
9
  changes
10
10
  end
11
11
 
12
- def stored_cia_changes(changes=nil)
12
+ def cia_previous_changes(changes=nil)
13
13
  if changes
14
- @stored_cia_changes = changes
14
+ @cia_previous_changes = changes
15
15
  else
16
- old, @stored_cia_changes = @stored_cia_changes, nil
16
+ old, @cia_previous_changes = @cia_previous_changes, nil
17
17
  old
18
18
  end
19
19
  end
@@ -38,7 +38,7 @@ module CIA
38
38
 
39
39
  [:create, :update, :destroy].each do |callback|
40
40
  method, args = if options[:callback] == :after_commit
41
- send("after_#{callback}"){ |record| record.stored_cia_changes(record.cia_changes) }
41
+ send("after_#{callback}"){ |record| record.cia_previous_changes(record.cia_changes) }
42
42
  if ActiveRecord::VERSION::MAJOR == 2
43
43
  ["after_commit_on_#{callback}", []]
44
44
  else # rails 3+
data/lib/cia/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CIA
2
- VERSION = '0.4.3'
2
+ VERSION = '0.4.4'
3
3
  end
data/spec/cia_spec.rb CHANGED
@@ -103,6 +103,15 @@ describe CIA do
103
103
  }.to_not change{ object.class.count }
104
104
  end
105
105
 
106
+ it "is ok with non-attribute methods passed into .audit if they are set as non-recordable" do
107
+ CIA.non_recordable_attributes = [:foo]
108
+ expect {
109
+ CIA.audit(:actor => User.create!, :foo => 'bar') {
110
+ object.save!
111
+ }
112
+ }.to change{ CIA::Event.count }.by(+1)
113
+ end
114
+
106
115
  context "nested classes with multiple audited_attributes" do
107
116
  let(:object){ NestedCar.new }
108
117
 
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,7 @@ RSpec.configure do |config|
6
6
  config.before do
7
7
  CIA::Event.delete_all
8
8
  CIA::AttributeChange.delete_all
9
+ CIA.non_recordable_attributes = nil
9
10
  end
10
11
  end
11
12
 
metadata CHANGED
@@ -1,32 +1,22 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cia
3
- version: !ruby/object:Gem::Version
4
- hash: 9
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 3
10
- version: 0.4.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Michael Grosser
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-01-10 00:00:00 Z
12
+ date: 2013-02-22 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description:
22
15
  email: michael@grosser.it
23
16
  executables: []
24
-
25
17
  extensions: []
26
-
27
18
  extra_rdoc_files: []
28
-
29
- files:
19
+ files:
30
20
  - .travis.yml
31
21
  - Appraisals
32
22
  - Gemfile
@@ -49,37 +39,35 @@ files:
49
39
  - spec/cia_spec.rb
50
40
  - spec/spec_helper.rb
51
41
  homepage: http://github.com/grosser/cia
52
- licenses:
42
+ licenses:
53
43
  - MIT
54
44
  post_install_message:
55
45
  rdoc_options: []
56
-
57
- require_paths:
46
+ require_paths:
58
47
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
48
+ required_ruby_version: !ruby/object:Gem::Requirement
60
49
  none: false
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- hash: 3
65
- segments:
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ segments:
66
55
  - 0
67
- version: "0"
68
- required_rubygems_version: !ruby/object:Gem::Requirement
56
+ hash: 4468237118319359723
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
58
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ segments:
75
64
  - 0
76
- version: "0"
65
+ hash: 4468237118319359723
77
66
  requirements: []
78
-
79
67
  rubyforge_project:
80
68
  rubygems_version: 1.8.24
81
69
  signing_key:
82
70
  specification_version: 3
83
- summary: Audit model events like update/create/delete + attribute changes + group them by transaction, in normalized table layout for easy query access.
71
+ summary: Audit model events like update/create/delete + attribute changes + group
72
+ them by transaction, in normalized table layout for easy query access.
84
73
  test_files: []
85
-