Module: CIA
- Defined in:
- lib/cia.rb,
lib/cia/event.rb,
lib/cia/version.rb,
lib/cia/auditable.rb,
lib/cia/attribute_change.rb
Defined Under Namespace
Modules: Auditable
Classes: AttributeChange, Event
Constant Summary
collapse
- VERSION =
'0.4.3'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.exception_handler ⇒ Object
Returns the value of attribute exception_handler.
10
11
12
|
# File 'lib/cia.rb', line 10
def exception_handler
@exception_handler
end
|
Class Method Details
.audit(options = {}) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/cia.rb', line 13
def self.audit(options = {})
old = Thread.current[:cia_transaction]
Thread.current[:cia_transaction] = options
yield
ensure
Thread.current[:cia_transaction] = old
end
|
.current_actor ⇒ Object
29
30
31
|
# File 'lib/cia.rb', line 29
def self.current_actor
current_transaction[:actor] if current_transaction
end
|
.current_actor=(user) ⇒ Object
25
26
27
|
# File 'lib/cia.rb', line 25
def self.current_actor=(user)
current_transaction[:actor] = user if current_transaction
end
|
.current_transaction ⇒ Object
21
22
23
|
# File 'lib/cia.rb', line 21
def self.current_transaction
Thread.current[:cia_transaction]
end
|
.record(action, source) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/cia.rb', line 33
def self.record(action, source)
return unless current_transaction
options = source.class.audited_attribute_options
return if options and options[:if] and not source.send(options[:if])
return if options and options[:unless] and source.send(options[:unless])
changes = (source.stored_cia_changes || source.cia_changes).slice(*source.class.audited_attributes)
message = source.audit_message if source.respond_to?(:audit_message)
return if not message and changes.empty? and action.to_s == "update"
event = CIA::Event.new(current_transaction.merge(
:action => action.to_s,
:source => source,
:message => message
))
event.add_attribute_changes(changes)
event.save!
event
rescue Object => e
if exception_handler
exception_handler.call e
else
raise e
end
end
|