Module: CIA
- Defined in:
- lib/cia.rb,
lib/cia/event.rb,
lib/cia/version.rb,
lib/cia/auditable.rb,
lib/cia/attribute_change.rb,
lib/cia/source_validation.rb
Defined Under Namespace
Modules: Auditable, SourceValidation
Classes: AttributeChange, Event
Constant Summary
collapse
- VERSION =
'0.5.4'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.exception_handler ⇒ Object
Returns the value of attribute exception_handler.
11
12
13
|
# File 'lib/cia.rb', line 11
def exception_handler
@exception_handler
end
|
.non_recordable_attributes ⇒ Object
Returns the value of attribute non_recordable_attributes.
12
13
14
|
# File 'lib/cia.rb', line 12
def non_recordable_attributes
@non_recordable_attributes
end
|
Class Method Details
.audit(options = {}) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/cia.rb', line 15
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
31
32
33
|
# File 'lib/cia.rb', line 31
def self.current_actor
current_transaction[:actor] if current_transaction
end
|
.current_actor=(user) ⇒ Object
27
28
29
|
# File 'lib/cia.rb', line 27
def self.current_actor=(user)
current_transaction[:actor] = user if current_transaction
end
|
.current_transaction ⇒ Object
23
24
25
|
# File 'lib/cia.rb', line 23
def self.current_transaction
Thread.current[:cia_transaction]
end
|
.record(action, source) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/cia.rb', line 35
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.cia_previous_changes || source.cia_changes).slice(*source.class.audited_attributes)
message = source.audit_message.presence if source.respond_to?(:audit_message)
return if not message and changes.empty? and action.to_s == "update"
transaction_attributes = current_transaction.dup
transaction_attributes.reject! { |k, v| non_recordable_attributes.include?(k) } if non_recordable_attributes
event = CIA::Event.new(transaction_attributes.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
|