Class: AuditTracker::Tracker
- Inherits:
-
Object
- Object
- AuditTracker::Tracker
- Defined in:
- lib/audit_tracker/tracker.rb
Overview
::AuditTracker::Tracker represents the tracker and is responsible for setting up the models to be tracked
I.e.:
tracker = Tracker.new(
create: [:created_by, class_name: "User", foreign_key: "created_by_id"]),
update: [:updated_by, class_name: "User", foreign_key: "updated_by_id"]),
value: -> { User.current }
)
tracker.apply(MyTrackedModel)
After applying, if MyTrackedModel represents a table that contains the necessary foreign keys, the relationships (‘created_by` and `updated_by`) and callbacks (before create / update) will be added to it.
::AuditTracker::Tracker is the core of AuditTracker, and a collection of trackers is built into AuditTracker.trackers via AuditTracker.setup.
Defined Under Namespace
Classes: Callback
Instance Method Summary collapse
- #apply(model, overrides) ⇒ Object
-
#initialize(on:, value:) ⇒ Tracker
constructor
A new instance of Tracker.
Constructor Details
#initialize(on:, value:) ⇒ Tracker
Returns a new instance of Tracker.
25 26 27 28 29 30 |
# File 'lib/audit_tracker/tracker.rb', line 25 def initialize(on:, value:) @on = on @value = value super() end |
Instance Method Details
#apply(model, overrides) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/audit_tracker/tracker.rb', line 32 def apply(model, overrides) @on.each do |event, relation, | = .merge(overrides[relation] || {}) apply_relation(model, relation, , event) end end |