Permalink
Browse files

Expose create_activity for public use and explain it in the docs

  • Loading branch information...
1 parent 9c3414f commit 7c0109bd5bf2df09f13097db954bb3c6cc3a6291 @pokonski pokonski committed Sep 8, 2011
Showing with 136 additions and 7 deletions.
  1. +109 −0 Gemfile.lock
  2. +19 −4 lib/public_activity/common.rb
  3. +8 −3 lib/public_activity/tracked.rb
View
@@ -0,0 +1,109 @@
+PATH
+ remote: .
+ specs:
+ public_activity (0.3)
+ activerecord (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ i18n (>= 0.5.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.0)
+ actionpack (= 3.1.0)
+ mail (~> 2.3.0)
+ actionpack (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.2)
+ rack-cache (~> 1.0.3)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.0)
+ activemodel (3.1.0)
+ activesupport (= 3.1.0)
+ bcrypt-ruby (~> 3.0.0)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ activesupport (3.1.0)
+ multi_json (~> 1.0)
+ arel (2.2.1)
+ bcrypt-ruby (3.0.0)
+ builder (3.0.0)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ mail (2.3.0)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ multi_json (1.0.3)
+ polyglot (0.3.2)
+ rack (1.3.2)
+ rack-cache (1.0.3)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.0)
+ actionmailer (= 3.1.0)
+ actionpack (= 3.1.0)
+ activerecord (= 3.1.0)
+ activeresource (= 3.1.0)
+ activesupport (= 3.1.0)
+ bundler (~> 1.0)
+ railties (= 3.1.0)
+ railties (3.1.0)
+ actionpack (= 3.1.0)
+ activesupport (= 3.1.0)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2)
+ rdoc (3.9.4)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ sprockets (2.0.0)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (!= 1.3.0, ~> 1.1)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.29)
+ yard (0.7.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ i18n
+ public_activity!
+ rails
+ rspec
+ yard
@@ -4,11 +4,26 @@ module Common
extend ActiveSupport::Concern
# Instance methods used by other methods in PublicActivity module.
module InstanceMethods
+ # Directly creates activity record in the database, based on supplied arguments.
+ # Only first argument - key - is required.
+ #
+ # == Usage:
+ #
+ # current_user.create_activity("activity.user.avatar_changed") if @user.avatar_file_name_changed?
+ #
+ # == Parameters:
+ # [key]
+ # Custom key that will be used as a i18n translation key - *required*
+ # [owner]
+ # Polymorphic relation specifying the owner of this activity (for example, a User who performed this task) - *optional*
+ # [params]
+ # Hash with parameters passed directly into i18n.translate method - *optional*
+ #
+ def create_activity(key, owner = nil, params = {})
+ self.activities.create(:key => key, :owner => owner, :parameters => params)
+ end
+
private
- # Creates activity based on supplied arguments
- def create_activity(key, owner, params)
- self.activities.create(:key => key, :owner => owner, :parameters => params)
- end
# Prepares settings used during creation of Activity record.
# params passed directly to tracked model have priority over
# settings specified in tracked() method
@@ -87,14 +87,19 @@ module ClassMethods
# method. It is later used in {Activity#text} method.
# == Example:
# @article.activity :parameters => {:title => @article.title, :short => truncate(@article.text, :length => 50)}
- # Everything specified here has a lower priority than parameters specified directly in {Tracked#activity} method.
+ # Everything specified here has a lower priority than parameters specified directly in {Tracked::InstanceMethods#activity} method.
# So treat it as a place where you provide 'default' values.
# For more dynamic settings refer to {Activity} model
# documentation.
+ # [:skip_defaults]
+ # Disables recording of activities on create/update/destroy leaving that to programmer's choice. Check {PublicActivity::Common::InstanceMethods#create_activity}
+ # for a guide on how to manually record activities.
def tracked(options = {})
include Common
- include Creation
- include Destruction
+ if !options[:skip_defaults]
+ include Creation
+ include Destruction
+ end
if options[:owner]
self.activity_owner_global = options[:owner]

0 comments on commit 7c0109b

Please sign in to comment.