Permalink
Browse files

project activity

  • Loading branch information...
1 parent 911c419 commit f2e8f395808d73880e69a9c52bde052c29738545 @stuartchaney committed Aug 17, 2012
Showing with 25 additions and 4 deletions.
  1. +3 −1 lib/public_activity/activity.rb
  2. +12 −2 lib/public_activity/common.rb
  3. +10 −1 lib/public_activity/tracked.rb
@@ -8,13 +8,15 @@ class Activity < ActiveRecord::Base
belongs_to :owner, :polymorphic => true
# Define ownership to a resource targeted by this activity
belongs_to :recipient, :polymorphic => true
+ belongs_to :project
+
# Serialize parameters Hash
serialize :parameters, Hash
class_attribute :template
# should recipient and owner be accessible?
- attr_accessible :key, :owner, :parameters, :recipient
+ attr_accessible :key, :owner, :parameters, :recipient, :project
# Virtual attribute returning text description of the activity
# using basic ERB templating
#
@@ -85,7 +85,8 @@ def create_activity(*args)
:key => options[:key],
:owner => options[:owner],
:recipient => options[:recipient],
- :parameters => options[:params]
+ :parameters => options[:params],
+ :project => options[:project]
)
end
end
@@ -126,6 +127,14 @@ def prepare_settings(*args)
self.class.activity_recipient_global
)
+ # project of the activity
+ project = PublicActivity.resolve_value(self,
+ options[:project] ||
+ self.activity_project ||
+ self.class.activity_project_global
+ )
+
+
#customizable parameters
params = options[:params] || {}
params.merge!(self.class.activity_params_global)
@@ -136,7 +145,8 @@ def prepare_settings(*args)
:key => key,
:owner => owner,
:recipient => recipient,
- :params => params
+ :params => params,
+ :project => project
}
end
end
@@ -5,9 +5,10 @@ module Tracked
included do
class_attribute :activity_owner_global, :activity_recipient_global,
- :activity_params_global, :activity_hooks
+ :activity_params_global, :activity_hooks, :activity_project
self.activity_owner_global = nil
self.activity_recipient_global = nil
+ self.activity_project_global = nil
self.activity_params_global = {}
self.activity_hooks = {}
end
@@ -93,6 +94,10 @@ module Tracked
attr_accessor :activity_key
@activity_key = nil
+ attr_accessor :activity_project
+ @activity_project = nil
+
+
# @!visibility private
@@activity_hooks = {}
@@ -128,6 +133,7 @@ def activity(options = {})
self.activity_owner = options[:owner] if options[:owner]
self.activity_params = options[:params] if options[:params]
self.activity_recipient = options[:recipient] if options[:recipient]
+ self.activity_project = options[:project] if options[:project]
nil
end
@@ -259,6 +265,9 @@ def tracked(options = {})
if options[:params]
self.activity_params_global = options[:params]
end
+ if options[:project]
+ self.activity_project_global = options[:project]
+ end
if options.has_key?(:on) and options[:on].is_a? Hash
self.activity_hooks = options[:on].delete_if {|_, v| !v.is_a? Proc}.symbolize_keys if RUBY_VERSION == "1.8.7"
self.activity_hooks = options[:on].select {|_, v| v.is_a? Proc}.symbolize_keys if RUBY_VERSION != "1.8.7"

0 comments on commit f2e8f39

Please sign in to comment.