Module: CIA::Auditable::ClassMethods
- Defined in:
- lib/cia/auditable.rb
Instance Method Summary collapse
Instance Method Details
#audit_attribute(*attributes) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cia/auditable.rb', line 22 def audit_attribute(*attributes) = (attributes.last.is_a?(Hash) ? attributes.pop : {}) setup_auditing_callbacks() self.audited_attributes = attributes.map(&:to_s) raise "cannot have :if and :unless" if [:if] && [:unless] self. = has_many :cia_events, :class_name => "CIA::Event", :as => :source has_many :cia_attribute_changes, :class_name => "CIA::AttributeChange", :as => :source end |
#setup_auditing_callbacks(options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cia/auditable.rb', line 35 def setup_auditing_callbacks() return if audited_attributes_callbacks_added self.audited_attributes_callbacks_added = true [:create, :update, :destroy].each do |callback| method, args = if [:callback] == :after_commit send("after_#{callback}"){ |record| record.stored_cia_changes(record.cia_changes) } if ActiveRecord::VERSION::MAJOR == 2 ["after_commit_on_#{callback}", []] else # rails 3+ [:after_commit, [{:on => callback}]] end else ["after_#{callback}", []] end send(method, *args) { |record| CIA.record(callback, record) } end end |