module PublicActivity::Tracked
Main module extending classes we want to keep track of.
Public Instance Methods
activity(options = {})
click to toggle source
A shortcut method for setting custom key, owner and parameters of {Activity} in one line. Accepts a hash with 3 keys: :key, :owner, :params. You can specify all of them or just the ones you want to overwrite.
Options¶ ↑
- :key
-
See {Common#activity_key}
- :owner
-
See {Common#activity_owner}
- :params
-
See {Common#activity_params}
- :recipient
-
Set the recipient for this activity. Useful for private notifications, which should only be visible to a certain user. See {Common#activity_recipient}.
@example
@article = Article.new @article.title = "New article" @article.activity :key => "my.custom.article.key", :owner => @article.author, :params => {:title => @article.title} @article.save @article.activities.last.key #=> "my.custom.article.key" @article.activities.last.parameters #=> {:title => "New article"}
@param options [Hash] instance options to set on the tracked model @return [nil]
# File lib/public_activity/roles/tracked.rb, line 32 def activity(options = {}) rest = options.clone self.activity_key = rest.delete(:key) if rest[:key] self.activity_owner = rest.delete(:owner) if rest[:owner] self.activity_params = rest.delete(:params) if rest[:params] self.activity_recipient = rest.delete(:recipient) if rest[:recipient] self.activity_custom_fields = rest if rest.count > 0 nil end