cia 0.1.0 → 0.1.1

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.1.0)
4
+ cia (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/MIGRATION.rb ADDED
@@ -0,0 +1,24 @@
1
+ create_table :audit_transactions do |t|
2
+ t.integer :actor_id, :null => false
3
+ t.string :actor_type, :null => false
4
+ t.string :ip_address
5
+ t.timestamp :created_at
6
+ end
7
+
8
+ create_table :audit_events do |t|
9
+ t.string :type, :source_type, :null => false
10
+ t.integer :audit_transaction_id, :source_id, :null => false
11
+ t.string :message
12
+ t.timestamp :created_at
13
+ end
14
+
15
+ create_table :audit_attribute_changes do |t|
16
+ t.integer :audit_event_id, :source_id, :null => false
17
+ t.string :attribute_name, :source_type, :null => false
18
+ t.string :old_value, :new_value
19
+ end
20
+
21
+ # DOWN
22
+ # drop_table :audit_transactions
23
+ # drop_table :audit_events
24
+ # drop_table :audit_attribute_changes
data/Readme.md CHANGED
@@ -1,30 +1,37 @@
1
- # Central Intelligent Auditing
1
+ Central Internal Auditing
2
+ ============================
3
+
4
+ Audit model events like update/create/delete + attribute changes.
2
5
 
3
- Audit model events like update/create/delete + attribute changes.<br/>
4
6
  - very normalized and queryable through table layout
5
- ```
6
- 1 Transaction (actor/ip/time/...)
7
- -> has many events (updated subject + message)
8
- -> has many attribute changes (changed password from foo to bar on subject)
9
- ```
10
7
  - actors and subjects are polymorphic
11
- - events come in different types like `ActiveAuditing::UpdateEvent`
8
+ - events come in different types like `CIA::UpdateEvent`
12
9
  - transactions wrap multiple events, a nice place to add debugging info like source/action/ip
13
10
  - works on ActiveRecord 2 and 3
14
11
 
12
+ Table layout:
13
+
14
+ 1 Transaction (actor/ip/time/...)
15
+ -> has many events (updated subject + message)
16
+ -> has many attribute changes (changed password from foo to bar on subject)
17
+
18
+
15
19
  Install
16
20
  =======
17
- gem install active_auditing
21
+ gem install cia
18
22
  Or
19
23
 
20
24
  rails plugin install git://github.com/grosser/cia.git
21
25
 
26
+ `rails g migration add_cia` + paste [Migration](https://raw.github.com/grosser/cia/master/MIGRATION.rb)
27
+
22
28
 
23
29
  Usage
24
30
  =====
25
31
 
26
32
  ```Ruby
27
33
  class User < ActiveRecord::Base
34
+ include CIA::Auditable
28
35
  audited_attributes :email, :crypted_password
29
36
  end
30
37
 
@@ -32,13 +39,16 @@ class ApplicationController < ActionController::Base
32
39
  around_filter :scope_auditing
33
40
 
34
41
  def scope_auditing
35
- Auditing.audit :actor => current_user, :ip_address => request.remote_ip do
42
+ CIA.audit :actor => current_user, :ip_address => request.remote_ip do
36
43
  yield
37
44
  end
38
45
  end
39
46
  end
40
47
 
41
-
48
+ # quick access
49
+ User.last.audit_events
50
+ changes = User.last.audit_attribute_changes
51
+ last_passwords = changes.where(:attribute_name => "crypted_password").map(&:new_value)
42
52
  ```
43
53
 
44
54
 
data/cia.gemspec CHANGED
@@ -3,7 +3,7 @@ name = "cia"
3
3
  require "#{name}/version"
4
4
 
5
5
  Gem::Specification.new name, CIA::VERSION do |s|
6
- s.summary = "Audit model events like update/create/delete + attribute changes + grouped them by transaction, in normalized table layout for easy query access."
6
+ s.summary = "Audit model events like update/create/delete + attribute changes + group them by transaction, in normalized table layout for easy query access."
7
7
  s.authors = ["Michael Grosser"]
8
8
  s.email = "michael@grosser.it"
9
9
  s.homepage = "http://github.com/grosser/#{name}"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/cia
3
3
  specs:
4
- cia (0.0.0)
4
+ cia (0.1.0)
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.0.0)
4
+ cia (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/lib/cia.rb CHANGED
@@ -23,7 +23,7 @@ module CIA
23
23
 
24
24
  def self.record_audit(event_type, object)
25
25
  CIA.current_transaction.record(event_type, object)
26
- rescue => e
26
+ rescue Object => e
27
27
  Rails.logger.error("Failed to record audit: #{e}\n#{e.backtrace}")
28
28
  raise e unless Rails.env.production?
29
29
  end
data/lib/cia/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CIA
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -7,25 +7,7 @@ ActiveRecord::Base.establish_connection(
7
7
  )
8
8
 
9
9
  ActiveRecord::Schema.define(:version => 1) do
10
- create_table :audit_transactions do |t|
11
- t.integer :actor_id, :null => false
12
- t.string :actor_type, :null => false
13
- t.string :ip_address
14
- t.timestamp :created_at
15
- end
16
-
17
- create_table :audit_events do |t|
18
- t.string :type, :source_type, :null => false
19
- t.integer :audit_transaction_id, :source_id, :null => false
20
- t.string :message
21
- t.timestamp :created_at
22
- end
23
-
24
- create_table :audit_attribute_changes do |t|
25
- t.integer :audit_event_id, :source_id, :null => false
26
- t.string :attribute_name, :source_type, :null => false
27
- t.string :old_value, :new_value
28
- end
10
+ eval(File.read('MIGRATION.rb'))
29
11
 
30
12
  create_table :cars do |t|
31
13
  t.integer :wheels
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,6 +21,7 @@ files:
21
21
  - Appraisals
22
22
  - Gemfile
23
23
  - Gemfile.lock
24
+ - MIGRATION.rb
24
25
  - Rakefile
25
26
  - Readme.md
26
27
  - cia.gemspec
@@ -58,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
59
  version: '0'
59
60
  segments:
60
61
  - 0
61
- hash: -3376077843642118516
62
+ hash: -3489209353501167635
62
63
  required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  none: false
64
65
  requirements:
@@ -67,12 +68,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
68
  version: '0'
68
69
  segments:
69
70
  - 0
70
- hash: -3376077843642118516
71
+ hash: -3489209353501167635
71
72
  requirements: []
72
73
  rubyforge_project:
73
74
  rubygems_version: 1.8.24
74
75
  signing_key:
75
76
  specification_version: 3
76
- summary: Audit model events like update/create/delete + attribute changes + grouped
77
+ summary: Audit model events like update/create/delete + attribute changes + group
77
78
  them by transaction, in normalized table layout for easy query access.
78
79
  test_files: []