redis-timeline
redis-timeline copied to clipboard
Tracking more fine-grained changes
Hi there! We love this gem, and are testing integrating this with our web application. For the most part, it works great for our purposes -- new objects, edited objects, etc. However, we have a few large objects -- for example, an Invoice -- that is edited/updated in pieces rather than entirely.
What's the best way to fire a track event for an :update for, say, a specific method call or change on a model?
Example:
class Invoice < ActiveRecord::Base
include Timeline::Track
track :send_invoice,
on: :update
def send_invoice
self.sent = true
self.save
end
end
In the above example, we would like to fire :send_invoice when the function is called. We explored using if: but quickly ran into issues, because its the action we want to track, not the state.
For example, suppose we added an if: Proc.new { self.sent == true }, that would trigger the :update event in the future if sent is true, if you were doing other updates to the Invoice model.
Thanks for any thoughts you might have! I think supporting something like this would be very powerful.
+1, please lord.
Just so I can understand what you're trying to do...
You want to create an activity named send_invoice
, which should only get created when the method of the same name is called?
Would being able to call a method to record the activity directly be useful for you?
I'm working on some changes to the library so that it isn't so reliant on callbacks and consequently, ActiveRecord. It would allow you to do something like...
class Invoice < ActiveRecord::Base
include Timeline::Track
def send_invoice
update_attributes sent: true
track :send_invoice
end
end
Or if you prefer to use a 'service' based approach, thereby decoupling the tracking from the object itself...
class SendInvoice
include Timeline::Track
def initialize(invoice)
@invoice = invoice
end
attr_reader :invoice
def run
invoice.update_attributes :sent, true
track :send_invoice, object: invoice
end
end
Great!! Thanks you for the solution :+1:
Has this been implemented yet? +1