cia 0.1.1 → 0.2.0
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/Gemfile.lock +1 -1
- data/MIGRATION.rb +8 -8
- data/Readme.md +2 -2
- data/gemfiles/rails2.gemfile.lock +1 -1
- data/gemfiles/rails3.gemfile.lock +1 -1
- data/lib/cia.rb +3 -3
- data/lib/cia/attribute_change.rb +2 -2
- data/lib/cia/auditable.rb +2 -2
- data/lib/cia/event.rb +3 -3
- data/lib/cia/transaction.rb +2 -2
- data/lib/cia/version.rb +1 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/MIGRATION.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
create_table :
|
1
|
+
create_table :cia_transactions do |t|
|
2
2
|
t.integer :actor_id, :null => false
|
3
3
|
t.string :actor_type, :null => false
|
4
4
|
t.string :ip_address
|
5
5
|
t.timestamp :created_at
|
6
6
|
end
|
7
7
|
|
8
|
-
create_table :
|
8
|
+
create_table :cia_events do |t|
|
9
9
|
t.string :type, :source_type, :null => false
|
10
|
-
t.integer :
|
10
|
+
t.integer :cia_transaction_id, :source_id, :null => false
|
11
11
|
t.string :message
|
12
12
|
t.timestamp :created_at
|
13
13
|
end
|
14
14
|
|
15
|
-
create_table :
|
16
|
-
t.integer :
|
15
|
+
create_table :cia_attribute_changes do |t|
|
16
|
+
t.integer :cia_event_id, :source_id, :null => false
|
17
17
|
t.string :attribute_name, :source_type, :null => false
|
18
18
|
t.string :old_value, :new_value
|
19
19
|
end
|
20
20
|
|
21
21
|
# DOWN
|
22
|
-
# drop_table :
|
23
|
-
# drop_table :
|
24
|
-
# drop_table :
|
22
|
+
# drop_table :cia_transactions
|
23
|
+
# drop_table :cia_events
|
24
|
+
# drop_table :cia_attribute_changes
|
data/Readme.md
CHANGED
@@ -46,8 +46,8 @@ class ApplicationController < ActionController::Base
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# quick access
|
49
|
-
User.last.
|
50
|
-
changes = User.last.
|
49
|
+
User.last.cia_events
|
50
|
+
changes = User.last.cia_attribute_changes
|
51
51
|
last_passwords = changes.where(:attribute_name => "crypted_password").map(&:new_value)
|
52
52
|
```
|
53
53
|
|
data/lib/cia.rb
CHANGED
@@ -11,14 +11,14 @@ require 'cia/attribute_change'
|
|
11
11
|
|
12
12
|
module CIA
|
13
13
|
def self.audit(options = {})
|
14
|
-
Thread.current[:
|
14
|
+
Thread.current[:cia_transaction] = Transaction.new(options)
|
15
15
|
yield
|
16
16
|
ensure
|
17
|
-
Thread.current[:
|
17
|
+
Thread.current[:cia_transaction] = nil
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.current_transaction
|
21
|
-
Thread.current[:
|
21
|
+
Thread.current[:cia_transaction] || NullTransaction
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.record_audit(event_type, object)
|
data/lib/cia/attribute_change.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module CIA
|
2
2
|
class AttributeChange < ActiveRecord::Base
|
3
|
-
self.table_name = "
|
3
|
+
self.table_name = "cia_attribute_changes"
|
4
4
|
|
5
|
-
belongs_to :event, :foreign_key => "
|
5
|
+
belongs_to :event, :foreign_key => "cia_event_id"
|
6
6
|
belongs_to :source, :polymorphic => true
|
7
7
|
|
8
8
|
validates_presence_of :event, :attribute_name, :source
|
data/lib/cia/auditable.rb
CHANGED
@@ -13,8 +13,8 @@ module CIA
|
|
13
13
|
self.audited_attributes = Set.new unless audited_attributes
|
14
14
|
self.audited_attributes += attributes.map(&:to_s)
|
15
15
|
|
16
|
-
has_many :
|
17
|
-
has_many :
|
16
|
+
has_many :cia_events, :class_name => "CIA::Event", :as => :source
|
17
|
+
has_many :cia_attribute_changes, :class_name => "CIA::AttributeChange", :as => :source
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/cia/event.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module CIA
|
2
2
|
class Event < ActiveRecord::Base
|
3
3
|
abstract_class
|
4
|
-
self.table_name = "
|
4
|
+
self.table_name = "cia_events"
|
5
5
|
|
6
6
|
belongs_to :source, :polymorphic => true
|
7
|
-
belongs_to :transaction, :foreign_key => :
|
8
|
-
has_many :attribute_changes, :foreign_key => :
|
7
|
+
belongs_to :transaction, :foreign_key => :cia_transaction_id
|
8
|
+
has_many :attribute_changes, :foreign_key => :cia_event_id
|
9
9
|
|
10
10
|
validates_presence_of :transaction, :source, :type
|
11
11
|
|
data/lib/cia/transaction.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module CIA
|
2
2
|
class Transaction < ActiveRecord::Base
|
3
|
-
self.table_name = "
|
3
|
+
self.table_name = "cia_transactions"
|
4
4
|
|
5
5
|
belongs_to :actor, :polymorphic => true
|
6
|
-
has_many :events, :foreign_key => :
|
6
|
+
has_many :events, :foreign_key => :cia_transaction_id
|
7
7
|
|
8
8
|
def record(event_type, source)
|
9
9
|
changes = source.changes.slice(*source.class.audited_attributes)
|
data/lib/cia/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
59
|
version: '0'
|
60
60
|
segments:
|
61
61
|
- 0
|
62
|
-
hash:
|
62
|
+
hash: 331448571299140438
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: '0'
|
69
69
|
segments:
|
70
70
|
- 0
|
71
|
-
hash:
|
71
|
+
hash: 331448571299140438
|
72
72
|
requirements: []
|
73
73
|
rubyforge_project:
|
74
74
|
rubygems_version: 1.8.24
|