Module: PublicActivity::Tracked

Extended by:
ActiveSupport::Concern
Defined in:
lib/public_activity/roles/tracked.rb

Overview

Main module extending classes we want to keep track of.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#activity(options = {}) ⇒ nil

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.

Examples:


@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"}

Parameters:

  • options (Hash) (defaults to: {})

    instance options to set on the tracked model

Returns:

  • (nil)

32
33
34
35
36
37
38
39
40
# 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